Redirect Unauthorized Page Access in MVC to Custom View

后端 未结 5 1725
温柔的废话
温柔的废话 2020-12-23 16:36

I have an MVC website in which access is based on various Roles. Once a user logs into the system they can see navigation to the pages for which they are authorized. However

5条回答
  •  抹茶落季
    2020-12-23 16:55

    I think you should create your own Authorize filter attribute which inherit of the default Authorize filter

    public class CustomAuthorize: AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
           filterContext.Result = new HttpUnauthorizedResult(); // Try this but i'm not sure
        }
    }
    

提交回复
热议问题