locked
How to Store a Session after the Login RRS feed

  • Question

  • User-1642741938 posted

    I want to store the session of a particular person after verifying the user name and password. Please give me the coding.

    Saturday, October 22, 2011 7:06 AM

Answers

  • User-693248168 posted
    Session["LoginName"]=txtLogin.Text;
    
    Session["LoginTime"]=DateTime.Now;
    
    
    
    
    
    To get back the session value
    
    
    
    string LoginName=Session["LoginName"].ToString();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:08 AM
  • User1648350404 posted
     //Storing UserName in Session
     Session["UserName"] = txtUser.Text;
    
    //Check weather session variable null or not
            if (Session["UserName"] != null)
            {
                //Retrieving UserName from Session
                lblWelcome.Text = "Welcome : " + Session["UserName"];
            }
            else
            {
             //Do Something else
            }

    See following:

    http://www.codeproject.com/KB/aspnet/ExploringSession.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:09 AM
  • User1648350404 posted
     //Storing UserName in Session
     Session["UserName"] = txtUser.Text;
    
    //Check weather session variable null or not
            if (Session["UserName"] != null)
            {
                //Retrieving UserName from Session
                lblWelcome.Text = "Welcome : " + Session["UserName"];
            }
            else
            {
             lblWelcome.Visible = false;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:22 AM
  • User1413134711 posted

    in else part write the code

    lblName.Visible=false;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:24 AM

All replies

  • User-693248168 posted
    Session["LoginName"]=txtLogin.Text;
    
    Session["LoginTime"]=DateTime.Now;
    
    
    
    
    
    To get back the session value
    
    
    
    string LoginName=Session["LoginName"].ToString();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:08 AM
  • User1648350404 posted
     //Storing UserName in Session
     Session["UserName"] = txtUser.Text;
    
    //Check weather session variable null or not
            if (Session["UserName"] != null)
            {
                //Retrieving UserName from Session
                lblWelcome.Text = "Welcome : " + Session["UserName"];
            }
            else
            {
             //Do Something else
            }

    See following:

    http://www.codeproject.com/KB/aspnet/ExploringSession.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:09 AM
  • User1413134711 posted

    Hi abdul

    Storing and retrieving a value in the Session is as simple as:

    VB

    Session("Name") = "John Doe"

    Session.Add("Name","John Doe")'retrieving

    Dim Name As String = Session("Name") 

    C# 

    Session["Name"] = "John Doe";//or

    Session.Add("Name","John Doe");//retrievingstring

    Name = (string)Session["Name"];

    Hope this will help you for depth knowledge follow below link

    http://www.codeproject.com/KB/aspnet/ExploringSession.aspx

    Saturday, October 22, 2011 7:14 AM
  • User-1642741938 posted

    if (Session["UserName"] != null) { //Retrieving UserName from Session lblWelcome.Text = "Welcome : " + Session["UserName"]; } else { //Do Something else }

    In else part, i have to hide the Label, how to hide that. Can you please give me the coding.

    Saturday, October 22, 2011 7:21 AM
  • User1648350404 posted
     //Storing UserName in Session
     Session["UserName"] = txtUser.Text;
    
    //Check weather session variable null or not
            if (Session["UserName"] != null)
            {
                //Retrieving UserName from Session
                lblWelcome.Text = "Welcome : " + Session["UserName"];
            }
            else
            {
             lblWelcome.Visible = false;
            }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:22 AM
  • User1413134711 posted

    in else part write the code

    lblName.Visible=false;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 22, 2011 7:24 AM
  • User-1642741938 posted

    I got the solution. Thanks for your reply, now i am clear.

    Saturday, October 22, 2011 7:34 AM