zoukankan      html  css  js  c++  java
  • Create and retrive session

    PersonSession person = new PersonSession(int.Parse(txtPersonId.Text), txtName.Text, int.Parse 

                                      (txtAge.Text),   chkEmailValidated.Checked);
    PersonSession.CreatePersonSession(person);

    ------------------------

    PersonSession person = PersonSession.GetPersonSession();
           if (person == null)

           {
                Response.Redirect("NotLogged.aspx");
           }

           else
                this.Person = person;

    public PersonSession Person { get; private set; }

    ------------------

    public class PersonSession

    {

     const string KEY = "personDetails";
        public int Id
        {
            get; private set;
        }
        public string Name
        {
            get; private set;
        }
        public int Age
        {
            get; private set;
        }
        public bool HasEmailValidated
        {
            get; private set;
        }
     public PersonSession(int id,string name,int age,bool emailValidated)
     {
            this.Id = id;
            this.Name = name;
            this.Age = age;
            this.HasEmailValidated = emailValidated;
     }
        public static PersonSession GetPersonSession()
        {
            return HttpContext.Current.Session[KEY] as PersonSession;
        }
        public static void CreatePersonSession(PersonSession person)
        {
            HttpContext.Current.Session[KEY] = person;
        } 

    }

  • 相关阅读:
    SQL Server 和Oracle 12C体系结构图
    SQL Server Latch
    MSSQL SSIS agent job运行出错
    sys.processes spid 和 blocked是同一个 session id
    黑苹果导致Windows时间不对或关机不断电
    MSSQL shrink数据库
    MSSQL 死锁或阻塞检测
    MSSQL不能shrink日志
    tomcat配置https协议
    ELK windows下部署测试
  • 原文地址:https://www.cnblogs.com/greencolor/p/1669524.html
Copyright © 2011-2022 走看看