Reputation: 4499
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 filterContext)
{
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.
Upvotes: 1
Views: 1290
Reputation: 246
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);
Upvotes: 1