【问题标题】:httperrors in web.configweb.config 中的 httperrors
【发布时间】:2011-11-28 08:40:09
【问题描述】:

当出现 503 服务不可用错误时,我正在尝试使用简单的 html 页面。

我在 web.config 的 system.webservers 下面使用

<httpErrors errorMode="Custom">
  <remove statuscode="503" substatuscode="-1">
  <error statuscode="503" responseMode="File" path="Views/Shared/IISError.htm">
</httpErrors>

这行不通。当我停止我的应用程序时,我仍然得到 IIS 默认页面。

我正在使用 mvc3,剃须刀应用程序。

【问题讨论】:

  • 试试&lt;httpErrors errorMode="Detailed"&gt;

标签: asp.net-mvc-3 razor


【解决方案1】:

我花了一段时间才弄明白……但我认为这可能会对您有所帮助:

首先要在 IIS 7 中配置错误,您需要使用以下部分:

  <system.webServer>
    <httpErrors existingResponse="Replace" defaultResponseMode="Redirect" errorMode="Custom">
      <remove statusCode="503"/>
      <error statusCode="503" responseMode="Redirect" path="Views/Shared/IISError.htm"/>          
    </httpErrors>
  </system.webServer>

此配置有效,但是您可能会收到一条错误消息,指出您无法覆盖 httpErrors 部分,如果是这种情况,请按照以下步骤操作:

  1. 打开C:\Windows\System32\inetsrv\config\applicationHost.config

  2. 变化:

    <section name="httpErrors" overrideModeDefault="Deny" />
    

    收件人:

    <section name="httpErrors" overrideModeDefault="Allow" />
    

【讨论】:

    【解决方案2】:

    问题是,您使用的是 VisualStudio Development Server 还是 IIS7 Express?

    如果您使用的是 Cassini (VSDS),那么您应该尝试使用

    <customErrors mode="On" >
      <error statusCode="503" redirect="/Views/Shared/Error.htm"/>
    </customErrors>
    

    因为 httpErrors 是一种新结构,只能由 IIS7 处理。您可以在以下位置找到更多信息:What is the difference between customErrors and httpErrors?http://www.iis.net/ConfigReference/system.webServer/httpErrors

    【讨论】:

    • 你如何让你的 IIS 抛出 503?如果您通过应用程序执行此操作,它将通过 Asp.Net 处理程序。 httpErrors 指令适用于不通过 Asp.Net 的内容
    • 我正在 IIS 中停止我的应用程序池。这显示了默认的 503 页面而不是我的页面。
    • 如果您要停止应用程序池,则无法在 web.config 中设置自定义错误。您需要在 IIS 中执行此操作。
    【解决方案3】:

    根据您的其中一个 cmets,您似乎正在停止应用程序池。

    如果您要停止应用程序池,则无法在 web.config 中设置自定义错误。您需要在 IIS 中执行此操作。

    【讨论】:

      【解决方案4】:

      在 Mvc 5.1.1 和 IIS 7.5 中,需要反斜杠来指示文件响应模式的子文件夹。

      C#:

      [HttpGet]
      [AllowAnonymous]
      public ActionResult Login()
      {
          try
          {
              var allowLogin = false;
      
              if(allowLogin == false)
                  return new HttpStatusCodeResult(403);
          }
      }
      

      Web.config:

      <system.web>
        <!--customErrors tag is not required -->
      </system.web>
      <httpErrors errorMode="Custom" existingResponse="Replace" defaultResponseMode="File" >
        <remove statusCode="400" subStatusCode="-1" />
        <remove statusCode="401" subStatusCode="-1" />
        <remove statusCode="403" subStatusCode="6" />
        <remove statusCode="403" subStatusCode="-1" />
        <remove statusCode="503" subStatusCode="-1" />
        <remove statusCode="500" subStatusCode="-1" />
        <clear/>
        <error statusCode="400" subStatusCode="-1" path="ErrorPages\400.html" />
        <error statusCode="401" subStatusCode="-1" path="ErrorPages\401.html" />
        <error statusCode="403" subStatusCode="6"  path="ErrorPages\Restrict.html" />
        <error statusCode="403" subStatusCode="-1" path="ErrorPages\403.html" />
        <error statusCode="503" subStatusCode="-1" path="ErrorPages\503.html" />
        <error statusCode="500" subStatusCode="-1" path="ErrorPages\500.html" />
      </httpErrors>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-01
        • 2011-08-27
        • 1970-01-01
        • 2020-12-20
        • 1970-01-01
        • 1970-01-01
        • 2014-07-09
        • 2014-10-05
        相关资源
        最近更新 更多