开发者

How can I return json data and then stop the corresponding action in my custom filter attribution ?

There is an a开发者_运维问答synchronous request that need authorize user. I want to authorize in filter attribution. If user can't login, return a json data that used to tell the client to callback a javascript function to popup the login window. how can I stop the action in filter attribution?


Create a custom ActionFilterAttribute. Override OnActionExecuting.

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
    {
        filterContext.Result = new EmptyResult();
        return;
    }

    base.OnActionExecuting(filterContext);
}

Instead of EmptyResult return whatever you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜