开发者

MVC How to return view in ActionFilterAttribute like ActionResult?

Is it even possible to return a view from an ActionFilterAttribute? Right now i just have it throw an error and in the OnException in the base controller reroutes to an error page. Would liek to show my NoAccess view like i do when theres an permissions problem inside an action, but have it occur from an attribute on the action.

    public sealed class UserHasPermissionAttribute : ActionFilterAttribute
    {
      public override void OnActionExecuting(ActionExecutingContext filt开发者_运维问答erContext)
      {
if(HasPermission == false){

//What are my options here a view?

}
}
}

Seen several sites an blogs, but none have explained well, or what i am looking for.


By the sounds of what you're using your action filter for, it sounds like perhaps you should be using the AuthorizeAttribute?

Alternatively you could try just redirecting in the OnActionExecuting method itself, using something like:

filterContext.HttpContext.Response.Redirect(errorUrl);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜