gpt4 book ai didi

configuration - IIS7 Web 服务器自定义错误 - 适用于本地但不适用于发布到生产环境

转载 作者:行者123 更新时间:2023-12-04 01:47:49 25 4
gpt4 key购买 nike

我正在构建一个带有自定义错误页面的新站点。我已经设置了我的 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>

最佳答案

默认情况下,IIS7 拦截由应用程序生成的 HTTP 状态代码,例如 4xx 和 5xx,这些代码是在管道上进一步生成的。

您可以告诉 IIS 只传递现有的响应,而不用自己的错误页面替换它:

<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
</system.webServer>
</configuration>

有关更多信息,请参阅:

HTTP Errors <httpErrors>

关于configuration - IIS7 Web 服务器自定义错误 - 适用于本地但不适用于发布到生产环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6101110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com