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