Reputation: 1337
I am using Session
variable throughout in my application and my timeout is 1 hour. Here I need to catch the exception for session expires in any global way across my application. Could anyone help for this.
Thanks in advance...
Upvotes: 2
Views: 3314
Reputation: 781
in the page_load event of you page or in master page write the following code,
if (Session["key"] == null)
{
Response.Redirect("Login_Page_Name");
}
Upvotes: 1
Reputation: 9986
On the top your page load, you can look for the session expiration.
if(Session["SomeValue"] == null)
Response.Redirect("Login.aspx");//Session Expired.
Alternatively you can redirect to a handler, that would perform your desired operation when session expiration is found.
Upvotes: 1
Reputation: 14216
You can handle this in session_end event in global.asax file. Also make sure you have checked before using sesison variables like
if (Session["YourKey"]!=null) { //do something }
Upvotes: 0