Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI i have developed a asp.net project with a User Logins.for that i previously used Static variable for store userName of the user and i got a terrible errorbecause static variable is only showed latest Login person userID.
E:X if jhon first Login to the system it shows John in the user ID and then if watson logged after the jhon., then Jhons Login automatically change as watson. i thought server creates separate instances for different users. i i was wrong on that occasion.Then i used session variable for store the userName of the Particular users who login to the system. Then i feel it is ok. but i just want to ensure if i use session variables for store userName , is it create separate instances(sessions) for each and every users with out duplicating same userName Like Static variables did? this could be a very fool question but guys i'm new to that session thing and i want to ensure it before Let the users to preform Live run.

E:x Code

XML
protected void btnSignIn_Click(object sender, ImageClickEventArgs e)
{
    if (Page.IsValid)
    {

        UserValidation UserV = new UserValidation();
        int a = UserV.check_Login(UNtxt.Text, PWtxt.Text, List_company_cmbo.Text);
        if (a == 1)
        {
            //Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Login is ok')</SCRIPT>");
            //Response.Write("<a href='WebForm1.aspx'></a> ");
            //  WebForm1 wb = new WebForm1();

            Session["caption"] = UserV.getFname(UNtxt.Text.Trim());
            Session["logged"] = "logged";
            Response.Redirect("Home.aspx");

        }



Then i called the session variable from Master Page as follows.

C#
protected void Page_Load(object sender, EventArgs e)
       {
           try
           {
               //U_Name.Text = UserValidation.F_name;
               if (Session["caption"] == null)
               {


               }
               else
               {
                   U_Name.Text = Session["caption"].ToString();

               }
              // string firstName = (string)(Session["First"]);
           }
           catch (Exception ex)
           {

               ErrorLog el = new ErrorLog();
               el.ErrorRegistry(ex, "AntronERPMaster.Master.cs", "cannot perse Login person name to page", "NA", "NA");

           }
       }




Thanks in Advance!!!
Posted

1 solution

i'm confused.are u get the username from session or not. please give declare detail
 
Share this answer
 
Comments
Hesha 17-Oct-12 8:38am    
from Session variable
U_Name.Text = Session["caption"].ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900