1
I am looking for a way to terminate my session and redirect the user to the login screen when my system der Timeout.
I tried to use Session.Abandon() according to some examples I researched. But I don’t 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 is executed only until : context.session.Abandon(); and does not redirect to the login screen unless I give refresh on the page.
I don’t know in Asp.net MVC, but in Webforms there is a file called
Global.asax
that every time the session inspires the methodvoid Application_End(object sender, EventArgs e)
is called.– Marconi
@Marconi Gloabal.asax also exists in Asp net mvc, this code is inside it, but it still doesn’t work. Thanks
– Mik3i4a5
Places a break point within the method.
– Marconi
I put the break point, but it doesn’t come to that point context.Response.Redirect("~/Account/Login");
– Mik3i4a5
Put on if to see if the conditions are meeting.
– Marconi