在AJAX处理会话超时 [英] Handling session timeout in ajax
本文介绍了在AJAX处理会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的MVC应用程序,我有以下的属性来检查登录的用户:
In my MVC app I have the following attribute that checks for logged on users:
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
....
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest())
{
filterContext.Result = new Http403Result();
filterContext.HttpContext.Response.StatusCode = 403;
}
...
}
Layout.cshtml
Layout.cshtml
$("body").ajaxError(
function (e, request, settings, exception) {
alert('in');
if (request.status == 403) {
window.location = '@Url.Action("LogOn", "Account", new {area = "", msg = "forbidden", returnUrl = HttpContext.Current.Request.RawUrl})' + window.location.hash;
return;
}
if (request.status == 500) {
window.location = '@Url.Action("AccessDenied", "Error")';
return;
}
if (request.status == 410) {
window.location = '@Url.Action("Deleted", "Error")';
return;
}
window.location = '@Url.Action("Index", "Error")';
});
但由于某种原因警报(IN),当403 code为(从Ajax请求)抛出永远不会被连打:
but for some reason alert("in") never gets hit even when 403 code is thrown (from ajax request):
推荐答案
在包裹准备DOM功能阿贾克斯错误事件
Wrap the Ajax Error event in DOM Ready function
$(document).ready(function () {
$(document).ajaxError(function (e, xhr, settings) {
debugger;
});
});
或 检查这里
Or check here
这篇关于在AJAX处理会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文