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;
        } 

    }

  • 相关阅读:
    C# 设计模式-桥接模式
    C# 设计模式-外观模式
    C# 设计模式-代理模式
    楼层导航奇葩问题解决
    楼层导航和回顶部
    回顾
    禁止右击选中
    安装客服在线系统
    csdn 分享私藏的18个黑科技网站,想找什么软件就找什么软件!!!
    eyoucms 模板
  • 原文地址:https://www.cnblogs.com/greencolor/p/1669524.html
Copyright © 2011-2022 走看看