我的asp.net MVC Web应用程序中有以下动作过滤器类,它执行自定义授权检查: -
public class CheckUserPermissionsAttribute : ActionFilterAttribute
{
public string Model { get; set; }
public string Action { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//code goes here….
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var viewResult = new JsonResult();
viewResult.Data = (new { IsSuccess = "Unauthorized", description = "You are not authorized to perform this Action." });
filterContext.Result = viewResult;
}
}
base.OnActionExecuting(filterContext);
}}}
我有以下ajax.actinolink,它将调用一个动作方法并执行授权检查: -
@Ajax.ActionLink("Show Related Servers", "CustomerServer","Customer",
new {customerID = Model.ORG_ID},
new AjaxOptions {
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "detail" ,
LoadingElementId = "progress",
OnSuccess="detailsuccess"}
Onsuccess脚本是: -
function detailsuccess(data) {
if (data.IsSuccess == "Unauthorized") {
jAlert(data.description, 'Unauthorized Access');
}}
动作方法是: -
[CheckUserPermissions(Action = "Read", Model = "Server")]
public ActionResult CustomerServer(int customerID,int page=1) {
但我遇到的问题是,如果操作过滤器返回Json对象,那么我的ajax链接中的Onsuccess脚本将不会收到Json对象,也不会显示JAlert,甚至Onsuccess脚本也不会触发?< / p>