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.
精彩评论