Asp.net 服务器错误请求错误特定页面,而不是错误详细信息

Asp.net 服务器错误请求错误特定页面,而不是错误详细信息,asp.net,vb.net,visual-studio-2010,Asp.net,Vb.net,Visual Studio 2010,当我在服务器上部署我的项目时,在某些情况下,我会得到一个错误页面,指示我应该创建一个自定义错误页面。我想知道我将如何实现服务器要求的这个自定义错误页面,以向我提供准确和有用的消息,或者更好地说,我将如何使错误仅显示在主页上 这是我在下面收到的错误消息 Runtime Error Description: An application error occurred on the server. The current custom error settings for this applicat

当我在服务器上部署我的项目时,在某些情况下,我会得到一个错误页面,指示我应该创建一个自定义错误页面。我想知道我将如何实现服务器要求的这个自定义错误页面,以向我提供准确和有用的消息,或者更好地说,我将如何使错误仅显示在主页上

这是我在下面收到的错误消息

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在默认情况下不显示错误的原因)


相反,您应该使用来记录所有错误并向您报告。

对此,您可以执行以下两种操作之一

您可以将响应中的第一个代码段添加到web.config,所有人都可以看到有关错误的信息。(我不建议这样做)



或者你可以创建任何你想要的页面。例如,将名为“mycustompage.htm”的页面添加到您的网站。简单地说:

<b>An Error has occured, please try again later.</b>
发生错误,请稍后再试。
通过将以下内容添加到web.config文件:

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

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