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

问题描述:

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

<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

我一直使用这种方法。首先,删除该错误的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> 
+0

能不能请你看我更新的问题。谢谢。 –

确保您已经在IIS中选择“自定义错误页”在错误页面设置。

  1. 登录到IIS Web服务器。
  2. 展开网站并选择您的网站名称。
  3. 从功能视图的IIS部分下选择错误页面。
  4. 选择404错误,并右键单击它。
  5. 选择“编辑特征设置”。
  6. 选择“自定义错误页面”并点击确定保存设置。

enter image description here