【问题标题】:httpErrors - Redirect 403 to HTML file - How to?httpErrors - 将 403 重定向到 HTML 文件 - 如何?
【发布时间】:2016-04-27 09:26:23
【问题描述】:

当我在我的应用程序中收到 403 错误时,我正在尝试重定向到 html 文件。这是由 IIS 处理的,所以我已将其添加到我的 Web 配置中:

<httpErrors errorMode="Custom" >
      <remove statusCode="403"/>
      <error statusCode="403" responseMode="File" path="/500.html"/>
    </httpErrors>

这给了我这个错误:

You do not have permission to view this directory or page.

但是,如果我将响应模式更改为ExecuteURL,它将重定向到页面。但它会显示 200 的 http 状态代码,而文件将保留 403 错误。我就是无法让它重定向到这个文件。

谁能帮我解决这个问题?

【问题讨论】:

    标签: redirect iis web-config http-error


    【解决方案1】:

    根据system.webserver/httperrors/error 配置节点(https://www.iis.net/configreference/system.webserver/httperrors/error) 的描述,将responseMode 属性设置为File 需要提供错误页面的绝对Windows 路径。如下例所示:

    <configuration>
       <system.webServer>
          <httpErrors errorMode="DetailedLocalOnly" defaultResponseMode="File" >
             <remove statusCode="500" />
             <error statusCode="500"
                prefixLanguageFilePath="C:\Contoso\Content\errors"
                path="500.htm" />
           </httpErrors>
       </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-20
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2012-01-04
      • 1970-01-01
      相关资源
      最近更新 更多