【问题标题】:Custom Error page asp.net mvc 4自定义错误页面 asp.net mvc 4
【发布时间】:2013-11-28 00:35:24
【问题描述】:

我试图重定向到拒绝访问 (403) 上的自定义错误页面,而 iis 表示它只是显示了默认丑陋的 403 页面我在我的 web.config 上进行了以下更改

<httpErrors>
  <remove statusCode="403"/>
  <error statusCode="403" path="ErrorManager/InsufcientPrivilage"/>
</httpErrors>

<customErrors mode="On">
  <error statusCode="403" redirect="ErrorManager/InsufcientPrivilage" />
  <error statusCode="404" redirect="ErrorManager/PageNotFound"/>

</customErrors>

奇怪的是 404 自定义错误页面正在工作,但 403 却没有

【问题讨论】:

    标签: asp.net-mvc-4 iis web-config iis-express


    【解决方案1】:

    你有没有尝试过这样的事情:

    <customErrors mode="On">
      <error statusCode="403" redirect="~/ErrorManager/InsufcientPrivilage" />
      <error statusCode="404" redirect="~/ErrorManager/PageNotFound"/>
    </customErrors>
    
    <system.webServer> 
        <httpErrors errorMode="Detailed" /> 
    </system.webServer>
    

    我建议您删除 httpErrors 子元素,因为 httpErrors 用于显示非 .net 应用程序的错误。在您的情况下,customErrors 元素就足够了。

    问候, 乌鲁斯

    【讨论】:

    • 嗨,我更新了我的答案。 (包括 ~/ 到重定向属性值的开头)
    • 最后我必须使用 HandleUnauthorizedRequest 方法进行重定向
    猜你喜欢
    • 2014-06-27
    • 2018-12-03
    • 2012-12-04
    • 2015-11-14
    • 2011-08-13
    • 1970-01-01
    • 2016-12-03
    • 2010-10-07
    • 2012-06-29
    相关资源
    最近更新 更多