I'm looking for a way to end my session and redirect the user to the login screen when my system TimeOut .
I tried to use Session.Abandon () according to some examples that I researched. But I do not know what I'm doing wrong. below is my code:
protected void Application_EndRequest(object sender, EventArgs e)
{
var context = new HttpContextWrapper(Context);
if (context.Response.StatusCode == 302 && context.Request.IsAjaxRequest())
{
var redirectLocation = context.Response.RedirectLocation.ToString();
context.Response.RedirectLocation = null;
context.Response.ContentType = "text/plain";
context.Response.Write("session_timeout;" + redirectLocation);
context.Session.Abandon();
context.Response.Redirect("~/Account/Login");
}
}
The code runs only until: context.Session.Abandon (); and does not redirect to the login screen unless I give refresh on the page.