首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IIS7 web服务器自定义错误-适用于本地,但不适用于发布到生产环境中

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

Stack Overflow用户
提问于 2011-05-24 02:08:31
回答 2查看 12.6K关注 0票数 11

我正在建立一个新的网站与自定义错误页面。我已经设置了我的web.config,并设置了我所有的页面。

当我在本地运行,并强制错误(页面找不到是一个简单的),这一切工作得很好。但是,当我发布到我的Windows Server2008 R2生产服务器,并输入一个坏页面时,它仍然将我带到默认的IIS7错误页面。

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

代码语言:javascript
复制
<?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 Server2008 R2有什么不同吗?

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

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-24 03:14:26

默认情况下,IIS7拦截由应用程序生成的状态码,比如4xx和5xx。

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

代码语言:javascript
复制
<configuration>
  <system.webServer>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

有关详细信息,请参阅:

HTTP Errors

票数 19
EN

Stack Overflow用户

发布于 2011-05-24 02:15:49

这是help

我想知道您是否也必须以这种方式注册自定义错误的路径。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6101110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档