我正在使用自定义错误页面构建新网站。我已经设置了我的web.config,并设置了所有页面。
当我在本地运行时,强制错误(找不到页面很容易),一切正常。但是,当我发布到我的Windows Server 2008 R2生产服务器并输入错误页面时,它仍然会将我带到默认的IIS7错误页面。
以下是我的web.config示例(我的页面都在那里):
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="On" defaultRedirect="~/ErrorGeneral">
<error statusCode="400" redirect="~/ErrorBadRequest" />
<error statusCode="401" redirect="~/ErrorUnathorized" />
<error statusCode="402" redirect="~/ErrorPaymentRequired" />
<error statusCode="403" redirect="~/ErrorForbidden" />
<error statusCode="404" redirect="~/ErrorItemNotFound" />
<error statusCode="405" redirect="~/ErrorMethodNotAllowed" />
<error statusCode="406" redirect="~/ErrorNotAcceptable" />
<error statusCode="412" redirect="~/ErrorPreconditionFailed" />
<error statusCode="500" redirect="~/ErrorInternalServerError" />
<error statusCode="501" redirect="~/ErrorNotImplemented" />
<error statusCode="502" redirect="~/ErrorBadGateway" />
</customErrors>
</system.web>
</configuration>
我做错了什么吗?它与Windows Server 2008 R2有何区别?
编辑:我发现这个问题是web.config文件中的附加信息,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="On" defaultRedirect="~/ErrorGeneral">
<error statusCode="400" redirect="~/ErrorBadRequest" />
<error statusCode="401" redirect="~/ErrorUnathorized" />
<error statusCode="402" redirect="~/ErrorPaymentRequired" />
<error statusCode="403" redirect="~/ErrorForbidden" />
<error statusCode="404" redirect="~/ErrorItemNotFound" />
<error statusCode="405" redirect="~/ErrorMethodNotAllowed" />
<error statusCode="406" redirect="~/ErrorNotAcceptable" />
<error statusCode="412" redirect="~/ErrorPreconditionFailed" />
<error statusCode="500" redirect="~/ErrorInternalServerError" />
<error statusCode="501" redirect="~/ErrorNotImplemented" />
<error statusCode="502" redirect="~/ErrorBadGateway" />
</customErrors>
</system.web>
<system.webServer>
<httpErrors>
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="412" subStatusCode="-1" />
<remove statusCode="406" subStatusCode="-1" />
<remove statusCode="405" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="401" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/Pages/ErrorItemNotFound.aspx" responseMode="ExecuteURL" />
<error statusCode="401" prefixLanguageFilePath="" path="/Pages/ErrorUnauthorized.aspx" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/Pages/ErrorForbidden.aspx" responseMode="ExecuteURL" />
<error statusCode="405" prefixLanguageFilePath="" path="/Pages/ErrorMethodNotAllowed.aspx" responseMode="ExecuteURL" />
<error statusCode="406" prefixLanguageFilePath="" path="/Pages/ErrorNotAcceptable.aspx" responseMode="ExecuteURL" />
<error statusCode="412" prefixLanguageFilePath="" path="/Pages/ErrorPreconditionFailed.aspx" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/Pages/ErrorInternalServerError.aspx" responseMode="ExecuteURL" />
<error statusCode="501" prefixLanguageFilePath="" path="/Pages/ErrorNotImplemented.aspx" responseMode="ExecuteURL" />
<error statusCode="502" prefixLanguageFilePath="" path="/Pages/ErrorBadGateway.aspx" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
</configuration>
答案 0 :(得分:19)
默认情况下,IIS7拦截HTTP状态代码,例如由管道上的应用程序生成的4xx和5xx。
您可以告诉IIS只传递现有的响应,而不用自己的错误页面替换它:
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>
有关详细信息,请参阅:
答案 1 :(得分:0)
这是help吗?
我想知道你是否还必须以这种方式注册自定义错误的路径。