问题 Elmah没有记录HttpRequestValidationException


在我的ASP.NET MVC2应用程序中,Elmah无法记录任何内容 HttpRequestValidationException (当您通过远程桌面登录Web服务器并以localhost方式浏览网站时除外)

例如,如果我输入 &#39 使用我得到的域名从我的电脑正常浏览到文本框

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".

Elmah日志中没有任何内容。

但是,如果我通过远程桌面登录到Web服务器并以localhost身份浏览网站,我可以看到完整的错误消息:

Server Error in '/' Application.
A potentially dangerous Request.Form value was detected from the client 

我知道为什么会显示不同的错误消息,这是因为我没有 <customErrors mode="Off"/> 我的web.config中的节点。但是没关系,我不希望向全世界显示完整的错误消息。

但我想要的是让Elmah在发生错误时记录此错误。我需要做些什么才能使其按预期工作?


6952
2018-05-16 22:31


起源



答案:


我认为这是Elmah的缺陷 http://code.google.com/p/elmah/issues/detail?id=217 这是由ASP.NET 4中请求验证的重大变化引起的。缺陷列出了两种可能的解决方法(通过在Application_Error处理程序中捕获异常或在Web.config中关闭新的验证行为来手动记录ELMAH中的异常)

看到这个 博客文章 提供解决方法。


12
2018-06-05 23:46



仅供参考:Application_Error似乎在IIS7中的集成管道模式下不起作用。 - Mike Cole


答案:


我认为这是Elmah的缺陷 http://code.google.com/p/elmah/issues/detail?id=217 这是由ASP.NET 4中请求验证的重大变化引起的。缺陷列出了两种可能的解决方法(通过在Application_Error处理程序中捕获异常或在Web.config中关闭新的验证行为来手动记录ELMAH中的异常)

看到这个 博客文章 提供解决方法。


12
2018-06-05 23:46



仅供参考:Application_Error似乎在IIS7中的集成管道模式下不起作用。 - Mike Cole