2
votes

I have got a problem with end session. All the time when I click button in "WebForms.asax" session count time from zero to one minute(if I will click this buton session will never end). I gave value 1 minute to end all sessions and it`s work when I not click on website. Do you know where is a problem?

here I start session:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Session_Test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["UserAuthentication"] = "dddd";
            TypSession.InnerHtml = "<a href='WebForm1.aspx'>sdsds</a>";
        }
    }
}

Another website (WebForm1.aspx):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Session_Test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            example.InnerHtml = Session["UserAuthentication"].ToString()+"         "+ Session.Timeout.ToString();;
        }

        protected void Unnamed1_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.RawUrl);
            Session.Abandon();

        }
    }
}

global.asax

 void Session_Start(object sender, EventArgs e)
        {
            Session.Timeout = 1; 
        }

        void Session_End(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:51888/Default.aspx");
        }
1

1 Answers

2
votes
Response.Redirect(Request.RawUrl);

Will end your respones, it is the same as calling:

Response.Redirect(Request.RawUrl, true);

where the bool stands for stop the response, so your Session.Abandon() will never be called. If you want to do Session.Abandon() after your redirect you should call redirect with false:

Response.Redirect(Request.RawUrl, false);

Redirect MSDN