我已成功添加自定义404页面。我想要做的是创建另一个自定义错误页面,当有404以外的任何错误时显示该错误页面。 500,403等。
这就是我现在在webconfig中所拥有的
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.aspx" responseMode="ExecuteURL"/>
</httpErrors>
答案 0 :(得分:9)
哦,我的。我无法相信我找不到这个简单问题的正确答案!然而,经过2个小时的阅读文档和调试,我找到了它。
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL" defaultPath="/App/Error"> <!-- Do not include ~, this was my issue all long -->
<clear/> <!-- so that IIS provided error pages are skipped -->
<!-- add those which you like to provide a view of yours -->
<error path="/App/Http404" responseMode="ExecuteURL" statusCode="404"/>
<error path="/App/Http503" responseMode="ExecuteURL" statusCode="503"/>
</httpErrors>
请注意<httpErrors>
配置IIS,而<customErrors>
配置ASP.NET和一些旧版本的IIS(&lt; = 6?)。
答案 1 :(得分:-1)
您可以在网络配置中使用customErrors:
<customErrors mode="On" defaultRedirect="~/DefaultError.aspx?msg=SomeMessage">
<error statusCode="404" redirect="~/PageNotFound.html"/>
<error statusCode="403" redirect="~/AccessDenied.html"/>
</customErrors>