Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i want to redirect to the login page from master page when session out.
If i am on a page inherit from a master page, when i click the button then
form do the postback. in master page Page_Load event i am checking if session
is no longer exist then redirct to the login page, but page do not redirect to the
login page, and button event execute, i don't want to place session out check mark every where .
So how can i redirct to the login page when user session out, from page load of master form?
Posted
Comments
faisal23 7-Nov-12 2:28am    
You have to use try catch block and when session expire redirect to login page from catch block

1 solution

In the Page_Load handler of your MasterPage, check for your session variable. If it's null, redirect to the login page:

C#
if(Session["MyVariable"] == null)
{
    FormsAuthentication.RedirectToLoginPage();
}


http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirecttologinpage.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900