Verify Session End

This is my base class for all pages except EndSession.aspx

override protected void OnInit(EventArgs e) { base.OnInit(e); if (Context.Session != null) { //check the IsNewSession value, this will tell us if the session has been reset. //IsNewSession will also let us know if the users session has timed out if (Session.IsNewSession) { //now we know it a new session, so we check to see if a cookie is present string cookie = Request.Headers["Cookie"]; //now we determine if there is a cookie does it contains what we're looking for if ((null != cookie) && (cookie.IndexOf("ASP.NET_SessionId") >= 0) )//&& !Request.QueryString["timeout"].ToString().Equals("yes")) { //since it a new session but a ASP.Net cookie exist we know //the session has expired so we need to redirect them Response.Redirect("EndSession.aspx?timeout=yes"); } } } } 

But at EndSession I try to go back, say default.aspx, and then this code above only redirects back to EndSession.aspx.

So, for a better clarification: Step 1: Go to the mypage.aspx page Step 2. Wait for the waiting time Step 3: try to go Step 4: redirect to EndSession.aspx Step 5: try to go Step 6: GoTo installed 4

Setp 6 should actually be able to get away ...

(if necessary, the pelaz will ask for further clarification)

Any ideas?

THANKS!!!

+4
source share
1 answer

I got rid of the base page, which was originally.

Put this in Session_Start from Global.asax

 void Session_Start(object sender, EventArgs e) { string cookie = Request.Headers["Cookie"]; // Code that runs when a new session is started if ((null != cookie) && (cookie.IndexOf("ASP.NET_SessionId") >= 0))//&& !Request.QueryString["timeout"].ToString().Equals("yes")) { if(Request.QueryString["timeout"] == null || !Request.QueryString["timeout"].ToString().Equals("yes")) Response.Redirect("Default.aspx?timeout=yes"); } } 

Put this on the Defualt.aspx page:

  if (!IsPostBack) { if (Request.QueryString["timeout"] != null && Request.QueryString["timeout"].ToString().Equals("yes")) { Response.Write("<script>" + "alert('Your Session has Timedout due to Inactivity');" + "location.href='Default.aspx';" + "</script>"); } } 

This solution works even when a timeout occurs on the Default.aspx page.

The discussion for the solution used is here: How to stop the base page from recursively detecting the session timeout

+4
source

All Articles