我的 ajax 调用有一个全局错误处理程序,如下所示:
$.ajaxSetup(
{
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert("error");
}
});
我正在像这样进行 ajax 调用:
@Ajax.ActionLink("Submit", "SubmitQuery", new AjaxOptions { HttpMethod = "POST" })
在 Controller 操作上,我有一个返回的 CustomAuthorizeAttribute:
filterContext.Result = new HttpStatusCodeResult(403, "adsfasd");
当用户未登录时。
出于某种原因,我的全局 jQuery AJAX 错误处理程序没有捕获 403 错误。
最佳答案
我设法弄明白了。
我需要:
filterContext.Result = new ContentResult
{
ContentType = "text/plain",
Content = "Access Denied. Invalid user name and/or password."
};
filterContext.HttpContext.Response.Status = "500 ".Replace("\r", " ").Replace("\n", " ");
关于c# - 使用 MVC 3 不显眼的 Javascript 进行全局 jQuery AJAX 错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5211908/