IIS7 Web服务器自定义错误 - 在本地工作,但不会发布到生产 [英] IIS7 web server custom errors - works on local but not when published to production

查看:88
本文介绍了IIS7 Web服务器自定义错误 - 在本地工作,但不会发布到生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个含有自订错误网页的新网站。

I am building a new site with custom error pages. I have setup my web.config, and have all of my pages setup.

当我在本地运行,并强制错误(找不到页面是容易的)一切都很好。但是当我发布到我的Windows Server 2008 R2生产服务器,并输入一个坏的页面,它仍然需要我到默认IIS7错误页面。

When I run locally, and force errors (page not found is the easy one), it all works well. But when I publish to my Windows Server 2008 R2 production server, and enter a bad page, it still takes me to the default IIS7 error page.

这里是一个示例我的web.config(和我的页面都在那里):

Here is a sample from my web.config (and my pages are all there):

<?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的区别吗?

Am I doing something simple incorrectly? Is it a difference with Windows Server 2008 R2?

编辑:我发现这个问题,这是web.config文件中的附加信息,如下所示: p>

I found the issue, which is additional information in the web.config file, to look like this:

<?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和

By default IIS7 intercepts HTTP status codes such as 4xx and 5xx generated by applications further up the pipeline.

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

You can tell IIS to just pass through the existing response without replacing it with its own error page:

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

有关详情,请参阅:


HTTP错误< httpErrors>

这篇关于IIS7 Web服务器自定义错误 - 在本地工作,但不会发布到生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆