I am using asp.net mvc and jquery to make ajax requests and when the session times out after an ajax request the full sigin page gets loaded into my ajax div.
How can I display a modal popup instead of making a redirect when a session times out?
I am using asp.net mvc and jquery to make ajax requests and when the session times out after an ajax request the full sigin page gets loaded into my ajax div.
How can I display a modal popup instead of making a redirect when a session times out?
One way to handle this that comes to mind is to use a custom HTTP header:
$.ajax({
url: '/home/someaction',
data: {},
success: function(html, status, xhr) {
if (xhr.getResponseHeader('REQUIRES_AUTH') === '1') {
alert('SESSION EXPIRED!!!');
} else {
$('#result').html(html);
}
}
});
And in your LogOn action you set the appropriate header:
public ActionResult LogOn()
{
Response.AddHeader("REQUIRES_AUTH", "1");
return View();
}
My solution is just five lines of JavaScript
$(document).ready(function () {
if ($("#site").length > 0) {
window.location = "<%= Url.Content("~") %>" + "Login/LogOn";
}
});
Put it on the login page. If is was loaded in a div on the main page, it will redirect til the login page. "#site" is a id of a div which is located on all pages except login page.