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

后端 未结 4 1749
盖世英雄少女心
盖世英雄少女心 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 02:08

    One good place for that kind of data would be in session. Try something like this on the first page:

    this.Session["UserName"] = userName;
    

    and then subsequent pages in that session for that user could access this.Session["UserName"].

    The best thing to do though is to create a static class to manage Session for you like so:

    using System;
    using System.Web;
    
    static class SessionManager
    {
        public static String UserName
        {
            get
            {
                return HttpContext.Current.Session["UserName"].ToString();
            }
            set
            {
                HttpContext.Current.Session["UserName"] = value;
            }
        }
    
            // add other properties as needed
    }
    

    Then your application can access session state like this:

    SessionManager.UserName
    

    This will give you maximum flexibility and scalability moving forward.

提交回复
热议问题