【问题标题】:customErrors with redirectMode="ResponseRewrite" do not work on shared hosting带有 redirectMode="ResponseRewrite" 的 customErrors 不适用于共享主机
【发布时间】:2011-10-14 13:58:42
【问题描述】:

我正在尝试为我的网站设置自定义错误页面(ASP.NET 4,集成管道)。

在本地机器上一切正常,但.aspx 页面的自定义错误页面不会显示在共享主机上(我看到默认错误页面)。

如果我将 redirectMode="ResponseRewrite" 更改为 redirectMode="ResponseRedirect" 一切都在本地和共享机器上正常工作。

error.aspx 是位于web.config 文件旁边的真实文件(在站点的根目录中)。站点没有Global.asax 文件。

本地机器运行 IIS 7.5,我不使用路由(至少有意识地)并且共享主机告诉 Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319

您能否告诉我造成这种不同行为的原因可能是什么以及我应该如何解决这个问题。

这是我的web.config文件的摘录:

<system.webServer>
    <httpErrors errorMode="Custom">
        <remove statusCode="404" />
        <error statusCode="404" path="/error.aspx" responseMode="ExecuteURL" />      
    </httpErrors>
</system.webServer>
<system.web>
    <customErrors mode="On" defaultRedirect="error.aspx" redirectMode="ResponseRewrite">
        <error statusCode="404" redirect="~/error.aspx"/>
    </customErrors>
    <httpRuntime requestValidationMode="2.0" />
</system.web>

【问题讨论】:

  • 你在本地运行什么? IIS 7 还是 7.5?自定义错误有几个不同之处。另外,你使用路由吗?
  • @ScottE local 我正在运行 IIS 7.5,但我不使用路由(至少有意识地)
  • 另外,请确保应用程序池未在经典模式与管道模式下运行,否则 system.webServer 部分不会受到影响。

标签: asp.net iis iis-7 iis-7.5 shared-hosting


【解决方案1】:

经过与托管服务提供商的长时间讨论,结果表明:

  • 我的方法很好
  • 但它不会按预期工作,因为 托管服务提供商通过 machine.config 禁用了此类功能

所以,永远不要低估提供者陷阱的数量。

【讨论】:

    【解决方案2】:

    我的 web.config 中有以下评论:

    对于 IIS 7.5,使用 errorMode="Custom";如果使用路由,则使用 responseMode="ExecuteURL",否则使用 responseMode="Redirect"

    别让我解释,因为我不知道!我只是通过反复试验来解决它。

    【讨论】:

    • httpErrors 部件在两台机器上都能正常工作。像 site.com/1 这样不存在的页面正在得到妥善处理。是customErrors 部分在共享主机上带来了意外行为(site.com/1.aspx 等页面未按预期处理)
    • /1 并不是真正的 .net 资源,所以我认为您必须使用:
    猜你喜欢
    • 2010-10-21
    • 1970-01-01
    • 2013-06-07
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 2019-07-29
    相关资源
    最近更新 更多