views:

98

answers:

3

I am using ASP.NET.

If my sessions time out i want to re-direct the page to another URL: Say the home page....

On my page I make use of a GridView that uses Session variables. If the session variable time expire(currently at 60min) and the user click on a row in the GridView I want to re-direct him/her to the home page of my site. Can this be done, how would I do this?

Thanks in advanced!

+5  A: 

Store some value in Session collection. Then check if it's still there at the next user's request. If not, redirect.

// Put some session marker

Session["IsOldSession"] = true;

// Then later...

if (Session["IsOldSession"] == null)
    Response.Redirect ("~/OMG.aspx");
Developer Art
+1 for exactly what I would do
Oded
Typed my answer and saw this one was there! :D
Senthil
Ai of course you are right, stupid me. I will add this code when the user click on the GridView SelectedIndexChanged event!
Etienne
+1  A: 

Alternatively you may simply rely on the the count of items in the session collection via using Session.Contents.Count. I would prefer this route over instantiating an additional item to persist in the session state collection.

If Session.Contents.Count = 0 Then
     Response.Redirect("~/default.aspx")
End If
Jakkwylde
A: 

Or just do this in your Page_Init()

if (Session.IsNewSession)
{
    Response.Redirect("homepage.aspx");
}
enderminh