Friday, January 16, 2009

Create Session in asp.net

Cretae Session:

Session["UserID"] = UserId;
Session.Timeout = 30;
FormsAuthenticationTicket formAuthenticate = new FormsAuthenticationTicket(1, UserId.ToString(), DateTime.Now, DateTime.Now.AddMinutes(30), true, FormsAuthentication.FormsCookiePath);
HttpCookie cookies = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(formAuthenticate));
cookies.Expires.AddYears(1);
Response.Cookies.Add(cookies);


Get Session:

string guidSession = HttpContext.Current.User.Identity.Name.ToString();