Advertisement

05.13.2008 at 05:34AM PDT, ID: 23397441
[x]
Attachment Details

Expired Session redirect problem

Asked by Prysson in Programming for ASP.NET, C# Programming Language

Tags: c#

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);


            //It appears from testing that the Request and Response both share the
            // same cookie collection.  If I set a cookie myself in the Reponse, it is
            // also immediately visible to the Request collection.  This just means that
            // since the ASP.Net_SessionID is set in the Session HTTPModule (which
            // has already run), thatwe can't use our own code to see if the cookie was
            // actually sent by the agent with the request using the collection. Check if
            // the given page supports session or not (this tested as reliable indicator
            // if EnableSessionState is true), should not care about a page that does
            // not need session
            if (Context.Session != null)
            {
                //Tested and the IsNewSession is more advanced then simply checking if
                // a cookie is present, it does take into account a session timeout, because
                // I tested a timeout and it did show as a new session
                if (Session.IsNewSession)
                {
                    // If it says it is a new session, but an existing cookie exists, then it must
                    // have timed out (can't use the cookie collection because even on first
                    // request it already contains the cookie (request and response
                    // seem to share the collection)
                    string szCookieHeader = Request.Headers["Cookie"];
                    if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                    {
                        Response.Redirect("SessionExpired.aspx");
                    }
                }
            }
        }
}

Start Free Trial
[+][-]05.13.2008 at 05:49AM PDT, ID: 21554468

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 06:04AM PDT, ID: 21554582

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 06:11AM PDT, ID: 21554666

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 06:34AM PDT, ID: 21554856

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.13.2008 at 12:43PM PDT, ID: 21558596

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, C# Programming Language
Tags: c#
Sign Up Now!
Solution Provided By: Prysson
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628