【问题标题】:Custom Error Page not showing自定义错误页面未显示
【发布时间】:2010-10-20 06:50:14
【问题描述】:

由于某种原因,当我收到 ASP.NET 运行时错误时,它没有加载我的自定义错误页面

<customErrors mode="On" defaultRedirect="app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="app_offline.htm"/>
        <error statusCode="500" redirect="app_offline.htm"/>
</customErrors>

这在我的 web.config 中。

我仍然得到这个,它没有加载我的错误 .htm 页面:

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

【问题讨论】:

  • 我将更新线程...我收到有关自定义错误的典型错误。这是托管在 discountasp.net 上
  • 为什么要使用 app_offline.htm 作为自定义错误?如果存在此文件首先会阻止您的 Web 应用程序。第二次打开错误,看看真正的错误。 (或查看您的日志)
  • 这就是交易。我不想修复错误。我想重定向到我的自定义错误页面并收工并上床睡觉。这应该重定向我!
  • 你有redirectMode="ResponseRewrite"是不是一个特殊的原因?当您遇到问题时,您应该首先尝试默认设置(redirectMode="ResponseRedirect",或完全删除该设置)。然后你可能会看到它实际上试图重定向到什么..
  • 在发布此主题之前,我已经尝试将其删除;与redirectMode无关

标签: asp.net


【解决方案1】:

我很确定 app_offline.htm 是 ASP.NET 中的保留文件名,如果存在于服务器上,它将始终提供服务。

尝试将其重命名为 error.htm 并更新您的 &lt;customErrors /&gt; 块以匹配。

【讨论】:

  • 不是这样的。我有完全相同的问题,我的页面名为 DisplayMyVeryOwnSpecialError.htm
  • 如果您阅读原始问题,您可以看到他将 app_offline.htm 配置为 defaultRedirect,以及将 redirect 配置为 404 和 500。app_offline.htm 将始终用作我说,所以答案是有效的。我怀疑你有一个不相关的问题。
  • 我认为您误读了一些信息,因为 app_offline.htm 所做的是它卸载了您的应用程序,如果该文件位于应用程序根目录中。显然他没有卸载应用程序的问题,而是没有显示错误页面。最重要的是,我认为 app_offline.htm 功能不像 CoffeeAddict 所说的那样存在于 .NET 3.5 中。
  • app_offline.htm 功能自 .Net 2.0 起就已在 ASP.NET 中。无论哪种方式,这都不会增加原始问题...他的问题是我们在 .Net 2.0 应用程序池中运行 .Net 4.0 应用程序。
【解决方案2】:

我怀疑发生的事情是 ASP.NET 找不到您的自定义错误页面。错误页面文件的路径必须是相对的或绝对的。所以要么:

<customErrors mode="On" defaultRedirect="~/app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="~/app_offline.htm"/>
    <error statusCode="500" redirect="~/app_offline.htm"/>
</customErrors>

或者:

<customErrors mode="On" defaultRedirect="http://mysite.com/app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="http://mysite.com/app_offline.htm"/>
    <error statusCode="500" redirect="http://mysite.com/app_offline.htm"/>
</customErrors>

应该可以解决你的问题。

【讨论】:

  • 你并不总是需要使用~。当然可以,但你也可以使用 redirect="app_offline.htm" 因为它已经在我的应用程序的根目录中,当我访问我的网站时我已经在打根目录了......不需要额外的〜
  • “当我访问我的网站时,我已经启动了 root...不需要额外的 ~” 是的,但是如果您访问的 URL 不是 相对于根目录并发生错误,则app_offline.htm 的相对路径将不再正确。不管怎样,很高兴你知道了。
【解决方案3】:

如果您设置 mode="Off",您会得到实际错误的详细信息吗?如果您仍然得到相同的默认错误页面,您可能会在这篇文章中找到解决方案:

CustomErrors mode="Off"

【讨论】:

    【解决方案4】:

    问题是我的网站在 .NET 3.5 下运行,而它是 4.0 应用程序

    【讨论】:

      【解决方案5】:

      我也有同样的问题。主要问题与您的错误页面对不同用户的可见性有关。它由标签控制

      模式

      如下图

      我认为您使用过 RemoteOnly 。为了在本地机器上运行时显示自定义错误页面,我们必须将 mode 值设为 On。对我来说,这是事后的工作。

      我们还可以为各种类型的错误代码提供错误页面。例如在下图中,您可以看到 - 我已将重定向页面指定为 CustomErrorAspxPage.aspx,用于状态码 404 的文件未找到异常类型。

      最后为了测试这一点,我创建了异常 1)默认异常 2)404 文件不存在异常,如下图所示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-10
        • 2013-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-28
        • 2016-08-18
        相关资源
        最近更新 更多