【发布时间】:2018-04-01 19:49:08
【问题描述】:
我在MVC 应用程序中配置了owin role-based 授权。
然后,我需要添加403http错误的自定义处理
我知道两种方法:
-
Web.config设置:<customErrors mode="Off" defaultRedirect="~/Error/" redirectMode="ResponseRedirect"> <error statusCode="403" redirect="~/Error/NoAccess" /> </customErrors> -
Authorize属性中覆盖的HandleUnauthorizedRequest方法内部的配置:if (filterContext.HttpContext.User?.Identity.IsAuthenticated ?? false) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { {"action", "NoAccess"}, {"controller", "Error"} }); //I've tried two variants of below: with below line as well as without it filterContext.Result.ExecuteResult(filterContext.Controller.ControllerContext); }
当我尝试访问我的用户不允许的资源并且我看到403 错误的自定义页面时,这两种方法在我的本地计算机上运行良好,但是当我在azure 上部署我的应用程序时门户网站,我只看到带有以下文本的白页:'您无权查看此目录或页面。'。据我所知,我需要在 azure 门户上配置此行为,并在我的代码中对其进行配置。
有人可以建议吗?
【问题讨论】:
标签: owin http-status-code-403 authorize-attribute azureportal role-base-authorization