Prabhakaran
Prabhakaran

Reputation: 1337

To handle Session expires exception

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

Answers (3)

Viral Sarvaiya
Viral Sarvaiya

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

Kamran Khan
Kamran Khan

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

Jalpesh Vadgama
Jalpesh Vadgama

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

Related Questions