IIS7 ASP.NET上不显示自定义错误页面

时间:2016-04-25 12:52:31

标签: c# asp.net .net iis error-handling

我想在我的网站上添加自定义错误页面。首先,我创建了一个测试Web项目,添加了两个测试页,将其发布到我的本地IIS并配置了web.config:

<configuration>
<system.web>
  <compilation targetFramework="4.0" />
  <customErrors mode="On" defaultRedirect="http://localhost:10000/apperror.aspx">
    <error statusCode="404" redirect="http://localhost:10000/404.aspx" />
  </customErrors>
</system.web> 

我可以单独浏览这些页面,但是当我尝试访问未找到的页面时:

  

http://localhost:10000/notfound.aspx

它完美无缺,并重定向到我的错误页面。但是当我在下面尝试时

  

http://localhost:10000/notfound

IIS显示自己的错误页面而不是我的自定义错误页面。我已搜索但未找到解决方案,你能帮我解决一下这个问题吗?

enter image description here

2 个答案:

答案 0 :(得分:2)

确保在IIS中的错误页面设置中选择了“自定义错误页面”。

  1. 登录IIS Web服务器。
  2. 展开网站并选择您的网站名称。
  3. 在功能视图的IIS下,选择错误页面。
  4. 选择404错误并右键单击它。
  5. 选择“编辑功能设置”。
  6. 选择“自定义错误页面”,然后单击“确定”以保存设置。
  7. enter image description here

答案 1 :(得分:1)

我总是使用这种方法。首先,从system.web中删除错误处理,然后添加:

<system.webServer>
    <httpErrors errorMode="DetailedLocalOnly" existingResponse="Replace">
        <remove statusCode="404" />
        <remove statusCode="500" />
        <error statusCode="404" responseMode="ExecuteURL" path="/Errors/NotFound" />
        <error statusCode="500" responseMode="ExecuteURL" path="/Errors/InternalError" />
    </httpErrors>
</system.webServer>
相关问题