Problem with session timeout redirect

Last post 05-13-2008 5:57 PM by Prysson. 2 replies.

Sort Posts:

  • Problem with session timeout redirect

    05-13-2008, 9:43 AM
    • Loading...
    • Prysson
    • Joined on 02-06-2007, 10:24 PM
    • Posts 97

    I have an expired session issue..

    I have a pasepage class that detects when a session is expired and redirects them to another page.

    This works fine...however..on the redirect page is a link to the default.aspx page. The idea is that they shoudl be able to go back to that page and restart the applkication with a new session.

    But all that happens is that it redetects that the session was expired and sends them back to the expired session page.

    Here is the code in the base page.

     

    public class BasePage : System.Web.UI.Page

    {

    public BasePage()

    {

    }

    override protected void OnInit(EventArgs e)

    {

    base.OnInit(e);

     

    if (Context.Session != null)

    {

    if (Session.IsNewSession)

    {

    string szCookieHeader = Request.Headers["Cookie"];if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))

    {

    string test = Request.Url.PathAndQuery;

    Response.Redirect("SessionExpired.aspx");

    }

    }

    }

    }

     

    The problem ultimately lies in this section

     

    string szCookieHeader = Request.Headers["Cookie"];if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))

    {

    string test = Request.Url.PathAndQuery;

    Response.Redirect("SessionExpired.aspx");

    }

     

    The reason I say its the problem is that on the sessionexpired.aspx page there is a link that redirects back to the defualt.aspx page. however when the default.aspx page loads if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0)) reevaluates back to true and so the response redirect back tot he sessionexpired page runs again./.its a loop I cant figure out how to break out of so the user can use teh application again.

     

  • Re: Problem with session timeout redirect

    05-13-2008, 3:55 PM

    I think, your problem lies with this

    if(Session.IsNewSession)

     Seems like, this part is getting evaluated to true even after you click the button on SessionExpired.aspx page, which it shouldnt

    Kumar Reddi
  • Re: Problem with session timeout redirect

    05-13-2008, 5:57 PM
    Answer
    • Loading...
    • Prysson
    • Joined on 02-06-2007, 10:24 PM
    • Posts 97

    Here is the solution. There is probably a better way to do it but this gets the job done at any rate.

    if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                        {
                            if (Session["exired"] != null)
                            {
                                string s = Session["exired"].ToString();
                            }
                            if (Session["exired"] != "true")
                            {

                                Session["expired"] = true;
                                Response.Redirect("SessionTimeout.aspx");
                            }
                            else
                            {
                                Session["expired"] = null;
                            }
                        }

Page 1 of 1 (3 items)