【发布时间】:2017-05-30 10:10:01
【问题描述】:
我想在 ASP.NET MVC 中针对 401 显示我的 web.config 错误页面,只有 404 和默认错误页面有效。身份验证过程是我自己的,不使用 .net 身份框架。
我在控制器操作方法中抛出了新的 401 异常。
行动:
[HttpGet]
[HandleError]
public ActionResult Delete(int id)
{
//if (user.IsInRole(RoleType.DELETE))
if (myOwnUserClass.IsInRole(RoleType.DELETE))
{
return View();
}
else
{
return new HttpStatusCodeResult(401);
//return PartialView("_unauthorize");
}
}
web.config
<customErrors mode="On" defaultRedirect="~/Error/Index">
<error statusCode="401" redirect="~/Error/Unauthorized" />
<error statusCode="404" redirect="~/Error/NotFound"/>
</customErrors>
我得到的是默认的 401 错误页面,不是我自己的。
Default 401 error page similar to this
我也为此搜索了 Stack Overflow,但这些答案对我不起作用。
【问题讨论】:
标签: asp.net-mvc custom-error-pages