0
votes

In my ASP.Net MVC 3.0 Application, I am accessing my Session variable allover the application. code

HttpContext.Session["CustomerID"]= customerID;

When any of the session variable is not available or null due to session time out, i would like to redirect the user to the login page.

How can i do it. because i am using Session variable allover the application i can't check the variables for null at each instance.

Any help would be greatly appreciated.

Thanks

1
You can use Session_End event in your Global.asax to redirect usersEmmanuel N
@EmmanuelN How would Session_End help here? It almost always runs when the user is not connected or making any request, and never runs in the context of a request.Andrew Barber

1 Answers

0
votes

I assume you want this to happen as soon as the session expires. To do this, you need some type of client side code (javascript) checking back with the server on some set time interval.

Create an action called IsServerExpired and have it return a json object containing a boolean value, and the redirect url.

Write a javascript function that checks back with the server and then do the redirect in javascript when the value returned is true.