session in class c# code example
Example 1: ession in class c#
HttpContext.Current.Session["loginId"]
Example 2: c# access session in class
public class MySession
{
private MySession()
{
Property1 = "default value";
}
public static MySession Current
{
get
{
MySession session =
(MySession)HttpContext.Current.Session["__MySession__"];
if (session == null)
{
session = new MySession();
HttpContext.Current.Session["__MySession__"] = session;
}
return session;
}
}
public string Property1 { get; set; }
public DateTime MyDate { get; set; }
public int LoginId { get; set; }
}