Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web.config上的customError源于服务器错误_Asp.net_Web Config - Fatal编程技术网

Asp.net web.config上的customError源于服务器错误

Asp.net web.config上的customError源于服务器错误,asp.net,web-config,Asp.net,Web Config,注意 我已经确定下面描述的问题是由于加载web.config文件中指定的DLL文件时遇到错误。我想提出一个用户友好的错误,即使是在web.config错误的情况下 结束注释 当我的ASP.Net应用程序遇到服务器错误时,我希望它向用户显示一条自定义错误消息,而不是下面的默认错误消息 Server Error in '/' Application. Runtime Error Description: An application error occurred on the server. T

注意

我已经确定下面描述的问题是由于加载
web.config
文件中指定的DLL文件时遇到错误。我想提出一个用户友好的错误,即使是在
web.config
错误的情况下

结束注释

当我的ASP.Net应用程序遇到服务器错误时,我希望它向用户显示一条自定义错误消息,而不是下面的默认错误消息

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,可以将当前看到的错误页替换为自定义错误页。 我编写了一个非常简单的HTML页面,并将其放在应用程序的根目录中。它被称为MaintenancePage.htm

我已将web.config文件设置为以下内容:

<customErrors mode="RemoteOnly" defaultRedirect="MaintenancePage.htm">
  <error statusCode="404" redirect="PageNotFound.aspx" />
</customErrors>

我还尝试了
~/MaintenancePage.htm
http://[mysite]/MaintenancePage.htm
。这些选项似乎都不起作用

我测试这个的方法是重命名我的项目所依赖的DLL,然后在web浏览器中加载该站点。我希望,由于存在错误,并且设置了
defaultRedirect
set,因此显示错误页面应该没有问题,但是,我显然错了

我已经搜索过这个问题,似乎大多数人都试图重定向到
aspx
页面,但在这样做时遇到了错误。许多人甚至报告说,他们无法将
aspx
页面作为
defaultRedirect
加载,但他们可以获取
html
页面加载

我在这里做错了什么


我应该注意,我是在公司防火墙之外的另一个网络上进行测试的,因此根据文档,将
RemoteOnly
更改为
On
。在测试中,将远程仅更改为开启时的没有预期效果。

将远程仅更改为开启时的

仅限远程:

指定自定义错误仅显示给远程客户端和 ASP.NET错误显示给本地主机

此外,您的URL可能是绝对的或相对的

要在本地观看它的工作,请执行以下操作:

<customErrors mode="On" defaultRedirect="/MaintenancePage.htm">
  <error statusCode="404" redirect="/PageNotFound.aspx" />
</customErrors>

更简单的测试方法

  • 尝试一个错误的url,并看着你的404错误接管
  • 将此内容放在您的default.aspx页面

  • 还有一件事需要考虑:错误日志记录。可以很容易地通过。

    我不只是在本地机器上进行测试,我也在远程机器上进行测试,我发现了同样的问题。我会看看你的其他建议,然后告诉你。谢谢。将
    RemoteOnly
    更改为
    On
    并没有像我在阅读文档后预期的那样做任何事情。我收到的错误是从远程位置测试页面的结果;也就是说,不是从服务器上。您从我的文章中复制了web.config的代码,然后尝试了测试2。。。并确保服务器上存在错误页?我确保错误页存在。我复制了你的web.config代码。然而,为了测试,我在bin文件夹中重命名了一个必需的DLL。当我转到一个不存在的页面时,我会看到我的错误页面。当我在
    default.aspx
    中放置异常时,我会在主模板中看到我的错误页面。