Do not use on any
shared computer
September 6, 2008 02:45pm pdt
 
[x]
Attachment Details

Help with Session timeout redirect

Tags: c#
I have an application and I am trying to code it so that when I have a session timeout and a user clicks in the application they get redirected to a session timeout web page. This page has a button that allows the user to return to the application(restart a session in the application)

All of my code works up until I try to redirect them back to the application start page...at that point it just detects that the session has timedout and redirects them back to the session timeout page.

I guess what I am trying to figure out is how to restart the session if the session has timed out...but I need to do it on a button click.

Below is the relevant code.

Default aspx.cs has this

    public partial class _Default : SessionCheck
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionCheck.RedirectUrl = "SessionTimeout.aspx";
        }

The Session Check class is as follows

public class SessionCheck : System.Web.UI.Page
    {
        /// <summary>  
        /// property vcariable for the URL Property  
        /// </summary>  
        private static string _redirectUrl;

        /// <summary>  
        /// property to hold the redirect url we will  
        /// use if the users session is expired or has  
        /// timed out.  
        /// </summary>  
        public static string RedirectUrl
        {
            get { return _redirectUrl; }
            set { _redirectUrl = value; }
        }

        public SessionCheck()
        {
            _redirectUrl = string.Empty;
        }

        override protected void OnInit(EventArgs e)
        {
            //initialize our base class (System.Web,UI.Page)  
            base.OnInit(e);
            //check to see if the Session is null (doesnt exist)  
            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's 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))
                    {
                        //since it's a new session but a ASP.Net cookie exist we know  
                        //the session has expired so we need to redirect them  
                        Response.Redirect("SessionTimeout.aspx?timeout=yes&success=no");
                    }
                }
            }
        }
    }

And finally the code on the button click where I am trying to restart the session and the application...

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

My guess is I need something in this response redirect to restart the session btu I dont know what that would be



Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: Prysson
Solution Provided By: rlively
Participating Experts: 2
Solution Grade: B
Views: 94
Translate:
Loading Advertisement...
 
[+][-]Accepted Solution by rlively
Accepted Solution by rlively:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by rlively
Expert Comment by rlively:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Prysson
Author Comment by Prysson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by rlively
Expert Comment by rlively:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Prysson
Author Comment by Prysson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Prysson
Author Comment by Prysson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Prysson
Author Comment by Prysson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by rlively
Expert Comment by rlively:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Prysson
Author Comment by Prysson:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by rlively
Expert Comment by rlively:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by nisarkhan
Expert Comment by nisarkhan:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628