【问题标题】:How to set .NET Error Pages for a specific folder in IIS 7?如何为 IIS 7 中的特定文件夹设置 .NET 错误页面?
【发布时间】:2014-12-15 15:13:36
【问题描述】:

可以将自定义错误页面应用到 IIS 中的特定文件夹吗?

比如我的文件夹名是http://my.com/foobar,在IIS里我右键文件夹名>>>.Net Error Pages Icon >>> Add... >>> 404 >>>> Absolute URL >>http://my.com/error.html

这不起作用。我签入了 web.config 文件。 IIS 也没有修改任何内容。我做错了吗?

~~~~~~~~~~~~~~~~ 我补充说:

我试过配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <customErrors>
            <error redirect="error.html" statusCode="403" />
        </customErrors>
    </system.web>
</configuration>

这不是围棋。

所以我尝试了

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <httpErrors errorMode="Custom" >
        <remove statusCode="403" subStatusCode="-1" />
        <error statusCode="403" path="http://my.com/err.html" responseMode="Redirect" />
        </httpErrors>
    </system.web>
</configuration>

这行得通,但这是添加到根目录下的 web.config 中,有没有办法为目录 web.config 添加?

【问题讨论】:

  • @huMptyduMpty 你好,请看我的更新,你能建议吗?谢谢。
  • 这个我自己没试过,但是文章里提到“如果选择Execute a URL on this site, path必须是相对于当前站点根目录的URL"
  • 我认为这不是路径问题,因为页面根本没有被重定向。然而我找到了另一种方法,它奏效了。不过还是谢谢。

标签: .net iis custom-error-pages


【解决方案1】:

我将此添加到目录 web.config 中,并且它起作用了。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
        <httpErrors errorMode="Custom" >
                                <remove statusCode="403" subStatusCode="-1" />
                                <error statusCode="403" path="`___REDIRECT URL HERE________`" responseMode="Redirect" />
                                </httpErrors>
   </system.webServer>
</configuration>

我的问题仍然存在:这与直接从 IIS 执行此操作的默认方式有何不同?像这样-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <customErrors>
            <error redirect="error.html" statusCode="403" />
        </customErrors>
    </system.web>
</configuration>

我听说这在 IIS6 中有效,但在 7/7.5 中无效?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    相关资源
    最近更新 更多