C# 自定义错误页未显示在IIS7 ASP.NET上
我想将自定义错误页面添加到我的站点。首先,我创建了一个测试web项目,添加了两个测试页面,将其发布到本地IIS并配置了web.config: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">
<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的错误页面设置中选择了“自定义错误页面”