Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自定义错误页未显示在IIS7 ASP.NET上_C#_Asp.net_.net_Iis_Error Handling - Fatal编程技术网

C# 自定义错误页未显示在IIS7 ASP.NET上

C# 自定义错误页未显示在IIS7 ASP.NET上,c#,asp.net,.net,iis,error-handling,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">

我想将自定义错误页面添加到我的站点。首先,我创建了一个测试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> 

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

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

IIS正在显示自己的错误页,而不是我的自定义错误页。我已经搜索了但没有找到解决方案,你能帮助我如何实现这一点吗


我总是使用这种方法。首先,从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>

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

  • 登录到IIS web服务器
  • 展开网站并选择您的网站名称
  • 从功能视图中,在IIS部分下选择错误页面
  • 选择404错误并右键单击它
  • 选择“编辑要素设置”
  • 选择“自定义错误页面”,然后单击“确定”保存设置