2011-05-16 65 views
11

在我的ASP.NET MVC2應用ELMAH無法登錄任何HttpRequestValidationExceptionELMAH沒有登錄HttpRequestValidationException

例如,如果我輸入&#39(當您登錄到通過遠程桌面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日誌中顯示。

但是,如果我登錄到通過遠程桌面Web服務器和瀏覽網站爲localhost我可以看到完整的錯誤消息:

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

我知道爲什麼顯示不同的錯誤信息,那是因爲我不t在我的web.config中有一個<customErrors mode="Off"/>節點。但沒關係,我不希望向全世界顯示完整的錯誤消息。

但我確實希望是當它發生時爲ELMAH記錄這個錯誤。我需要做些什麼才能使其按預期工作?

回答

12

我覺得這是這個ELMAH缺陷http://code.google.com/p/elmah/issues/detail?id=217,這是由ASP.NET 4缺陷列表中請求驗證打破變化引起的兩種可能的解決方法(在Application_Error事件處理程序捕獲它手動登錄ELMAH異常或關閉在Web.config新的驗證行爲)

看到這個blog post提供了一個解決方法。

+1

僅供參考:在IIS7中,Application_Error似乎不能在集成管道模式下工作。 – 2013-06-20 14:07:26