我的 MVC 项目根目录中的 web.config 文件中确实存在自定义错误。
<customErrors mode="On" defaultRedirect="~/Error">
<error statusCode="403" redirect="~/Error/UnauthorizedAccess" />
<error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>
但是,当我在 IIS 7 中部署项目时,任何浏览 Web 应用程序的尝试都会在浏览器中产生此错误:
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>
在我的应用程序中,我处理了错误并记录了它们,还给一些团队成员发了电子邮件。当我在 Visual Studio 或本地运行应用程序时,所有这些都有效。但是当我浏览这个新部署的应用程序时,没有创建日志,也没有发送任何电子邮件。
更新
有趣的是,它确实进入了我的应用程序的错误处理程序。我知道这是因为地址栏上写着:
http://10.1.17.43/MyApp/Error?aspxerrorpath=/MyApp
我的应用程序中处理所有异常Error
的控制器 ( ) 在哪里。ErrorController