我创建一个自定义角色提供程序,我设置了授权属性指定角色在我的控制器,它的工作很好,像这样:
[Authorize(Roles="SuperAdmin")] public class SuperAdminController : Controller ...
解决方法
[AccessDeniedAuthorize(Roles="SuperAdmin")] public class SuperAdminController : Controller
AccessDeniedAuthorizeAttribute.cs:
public class AccessDeniedAuthorizeAttribute : AuthorizeAttribute { public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); if(filterContext.Result is HttpUnauthorizedResult) { filterContext.Result = new RedirectResult("~/AcessDenied.aspx"); } } }