ASP.Net部分忽略了web.config中的自定义错误部分

时间:2009-12-01 15:36:05

标签: asp.net web-config

这是我的web.config customErrors部分(您会注意到我已将模式切换为'On',因此我可以看到我的localhost上的重定向):

    <customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On" redirectMode="ResponseRewrite">
        <error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
    </customErrors>

这是抛出的代码:

        Catch adEx As AccessDeniedException

              Throw New HttpException(DirectCast(HttpStatusCode.Forbidden, Integer), adEx.Message)

        End Try

这就是我最终的结果:

alt text

这不是我漂亮的AccessDenied.aspx页面,但它是一个禁止的错误页面,所以至少我知道我的投掷工作正在进行。

我已经删除了IIS(7.0)中403的条目作为绝望的最后一次尝试,并且毫无疑问这没有任何区别。

我现在已经没有想法了,所以任何建议都会感激不尽!

2 个答案:

答案 0 :(得分:0)

事实上,您的aspx页面可能根本没有执行。
转到IIS。 转到您的默认网站属性。 单击主目录选项卡 单击配置按钮。 现在,检查.aspx页面是否在那里注册。

答案 1 :(得分:0)

您需要在httpErrors元素的system.webServer部分指定existingResponse="PassThrough"

<configuration>
   <system.webServer>
       <httpErrors existingResponse="PassThrough" />
   </system.webServer>
</configuration>