Wednesday, June 29, 2011

Check for null session

Check for null session

1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (Session["UserName"] != null)
4 {
5 //do something
6 }
7 else
8 {
9 Session.Abandon();
10 // sign out the user
11 System.Web.Security.FormsAuthentication.SignOut();
12 // redirect to the login page
13 System.Web.Security.FormsAuthentication.RedirectToLoginPage();
14 }
15 }

No comments: