0

What would be the best way to detect if the SessionState has died in order to send the user to a "Session Expired" page? or redirect to another page?

I got a IIS 7 server and a application on ASP.net C#.

How can I do this?

I'm using this, I want redirect past the 30 minuts.

Praxusa
  • 77
  • 8
  • It would be helpful to see what you've managed to do so far, as well as any errors that you've encountered. – crthompson Jun 09 '14 at 23:07
  • 1
    Does your page require user authentication? Session State is not the same as User Authentication, FYI... see for example here: http://stackoverflow.com/questions/17812994/forms-authentication-timeout-vs-sessionstate-timeout – Icarus Jun 09 '14 at 23:10
  • Based on you comments I believe you are looking for forms authentication expiration - duplicate question show the code to do so. – Alexei Levenkov Jun 10 '14 at 16:35

1 Answers1

0

Session will be empty if it is expired or brand new one.

So you can check for presence of any custom property and if it is not present redirect to "welcome to my site" or "session expired" depending on your expectation for particular request.

  if (Session["RandomName"] == null && IsPostback)
     Redirect("data/is/lost/forever");
  Session["RandomName"] = "Here";
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • yeah but I'm not using the method Session of C#, what I'm using is a session handled by the IIS7 (sorry for my english xD) – Praxusa Jun 10 '14 at 14:16
  • @user3724088 "session handled by the IIS7"? Can you please provide an explanation of that (or better some link that talks about it)? – Alexei Levenkov Jun 10 '14 at 16:07
  • ok ok, I'm usign User.Identity.IsAuthenticated with the cookies in the browser, with this on the web.config – Praxusa Jun 10 '14 at 16:29
  • @user3724088 have you seen Icarus comment? I strongly suspect you talking about authentication. – Alexei Levenkov Jun 10 '14 at 16:33
  • But I want to know when the session expire, because I'm using JS code, and if I don't refresh or redirect to another page, the user can stay using this page with the JS because it's on the client side – Praxusa Jun 10 '14 at 17:34