In my ASP.NET MVC2 application Elmah fails to log any HttpRequestValidationException
(except when you are logged into the webserver via remote desktop and browsing the site as localhost)
For example if I type '
into a textbox when browsing normally from my pc using the domain name I get
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".
And nothing shows in the Elmah log.
But if I log into the webserver via remote desktop and browse the site as localhost I can see the full error message:
Server Error in '/' Application.
A potentially dangerous Request.Form value was detected from the client
I know why different error messages are shown, it is because I don't have a <customErrors mode="Off"/>
node in my web.config. But that's ok, I do not want the full error message shown to the whole world.
But what I do want is for Elmah to log this error when it occurs. What do I need to do to get this to work as expected?
Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.
In this article ELMAH is a free, open source error logging library that includes features like error filtering and the ability to view the error log from a web page, as an RSS feed, or to download it as a comma-delimited file.
I think this is this Elmah defect http://code.google.com/p/elmah/issues/detail?id=217 , which is caused by a breaking change in request validation in ASP.NET 4. The defect lists two possible workarounds (manually log the exception in ELMAH by catching it in the Application_Error handler or turning off the new validation behavior in the Web.config)
See this blog post providing a workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With