Asp.net 自定义错误页未显示

Asp.net 自定义错误页未显示,asp.net,Asp.net,由于某些原因,当我遇到ASP.NET运行时错误时,它不会加载我的自定义错误页 <customErrors mode="On" defaultRedirect="app_offline.htm" redirectMode="ResponseRewrite"> <error statusCode="404" redirect="app_offline.htm"/> <error statusCode="500" redirect="app_off

由于某些原因,当我遇到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中

但我仍然收到此消息,并且它没有加载我的error.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>
“/”应用程序中出现服务器错误。 运行时错误 描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,本地服务器上运行的浏览器可以查看它。 详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建一个标记。然后,该标记的“mode”属性应设置为“Off”。 注意:通过修改应用程序配置标记的“defaultRedirect”属性以指向自定义错误页URL,可以将当前看到的错误页替换为自定义错误页。
我怀疑发生的是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>

或:



应该可以解决您的问题。

如果设置mode=“Off”,您是否可以获得实际错误的详细信息?如果您仍然获得相同的默认错误页面,您可能会在本文中找到解决方案:


我确信app_offline.htm是ASP.NET中的一个保留文件名,如果在服务器上出现,它将始终被提供


尝试将其重命名为error.htm并更新您的
块以匹配。

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

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

模式

如下图所示

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

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

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

我将更新线程…我得到关于自定义错误的典型错误。这是在discountasp.netWhy上托管的。您为什么要将app_offline.htm用作自定义错误?首先,此文件(如果存在)正在停止您的web应用。其次,打开错误以查看真正的错误。(或者看看你的日志)事情是这样的。我不想纠正这个错误。我想重定向到我的自定义错误页面,结束这一天,然后睡觉。这应该是重定向我!这是您使用重定向模式=“ResponseWrite”的特殊原因吗?遇到问题时,应首先尝试默认设置(即
redirectMode=“ResponseRedirect”
,或完全删除该设置)。然后你可能会看到它实际上试图重定向到什么..在我发布这个帖子之前,我已经尝试过去掉它了;与重定向模式无关,您并不总是需要使用~。当然可以,但您也可以使用redirect=“app_offline.htm”,因为它已经在我的应用程序的根目录中,当我访问我的站点时,我正在点击根目录…不需要额外的~“当我访问我的站点时,我正在点击根目录…不需要额外的~”是的,但是如果您访问的URL与根目录无关,则会发生错误,然后,
app_offline.htm
的相对路径将不再正确。不管怎样,很高兴你明白了,不是这样。我有完全相同的问题,我的页面名为DisplayMyVeryOwnSpecialError.html如果您阅读原始问题,您可以看到他将app_offline.htm配置为
defaultRedirect
,以及404和500的
redirect
。app_offline.htm将始终按照我所说的那样提供,因此答案是有效的。我怀疑你有一个不相关的问题。我想你误读了一些信息,因为app_offline.htm所做的是卸载了你的应用程序,如果文件在app root目录中。显然,他对卸载的应用程序没有问题,而是错误页面没有显示。除此之外,我认为app_offline.htm功能并不像CoffeeAddict所说的那样出现在.NET3.5中。app_offline.htm功能从.NET2.0开始就出现在ASP.NET中。不管怎样,这都没有给原来的问题增加什么。。。他的问题是我们在.NET2.0应用程序池中运行.NET4.0应用程序。
<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>