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

    }

  • 相关阅读:
    docker tar 镜像 容器相互转换
    JavaScript执行上下文
    JavaScript 作用域
    原型与原型链
    使用Navicat for Oracle新建表空间、用户及权限赋予
    PL/SQL Developer使用教程(中文)
    一步一步使用bootstrap开发一个博客模板
    How to create a simple blog using ASP.NET MVC
    一个有意思的编程网站
    一个很好的java编程国外网站
  • 原文地址:https://www.cnblogs.com/greencolor/p/1669524.html
Copyright © 2011-2022 走看看