pass values or data from one page to another when you use Login control in ASP.NET 2.0

后端 未结 4 1577
盖世英雄少女心
盖世英雄少女心 2021-01-26 01:12

I am using Login Control available in ASP.NET 2.0 in the login page. Once the user is authenticated successfully against database, I am redirecting the user to home.aspx. Here,

4条回答
  •  一个人的身影
    2021-01-26 01:56

    yes as Andrew said, session is the primary place to store sensitive data.

    but why a user's name is sensitive ? You can save it in cookie and print it in your home.aspx whenever user comes in.

    EDIT : You can use cookies in ASP.NET like that :

    // Setting cookie : 
    Response.Cookies["UserName"].Value = "Erhan";
    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(7); // Persists 1 week
    
    // Getting cookie : 
    string username = string.Empty;
    if(Request.Cookies["UserName"] != null)
    {
        username = Server.HtmlEncode(Request.Cookies["UserName"].Value);
    }
    

    NOTE : Cookies stored at client's machine. so you should not use them to store sensitive data.

提交回复
热议问题