在我的ASP.NET MVC2应用程序中,Elmah无法记录任何HttpRequestValidationException
(除非您通过远程桌面登录Web服务器并以localhost方式浏览网站)
例如,如果我使用域名从我的电脑正常浏览时将'
键入文本框
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日志中没有任何内容。
但如果我通过远程桌面登录网站服务器并以localhost身份浏览网站,我可以看到完整的错误消息:
Server Error in '/' Application.
A potentially dangerous Request.Form value was detected from the client
我知道为什么会显示不同的错误消息,这是因为我的web.config中没有<customErrors mode="Off"/>
节点。但是没关系,我不希望向全世界展示完整的错误信息。
但我想要的是让Elmah在发生错误时记录此错误。我需要做些什么才能让它按预期工作?
答案 0 :(得分:12)
我认为这是Elmah缺陷http://code.google.com/p/elmah/issues/detail?id=217,这是由ASP.NET 4中请求验证的重大变化引起的。缺陷列出了两种可能的解决方法(通过在ELMAH中捕获它来手动记录ELMAH中的异常) Application_Error处理程序或关闭Web.config中的新验证行为
请参阅此blog post,提供解决方法。