ASP.NET
httprequestvalidationexception Data
Gravatar is a globally recognized avatar based on your email address. httprequestvalidationexception Data
  Bill
  All
  Jun 18, 2019 @ 06:25am

Is it possible to capture the offending text from a httprequestvalidationexception in the Global.asax.cs Application_Error() method for logging purposes? Or does the ASP.NET handler discard the data for security purposes? Tried the (Inner)Exception.Data dictionary but it was empty.

Gravatar is a globally recognized avatar based on your email address. re: httprequestvalidationexception Data
  Rick Strahl
  Bill
  Jun 18, 2019 @ 04:55pm

You should be able to capture it - unless it's IIS's request validation that's capturing the request in which case your exception handler doesn't fire.

Make sure nothing else is clearing the exception first.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: httprequestvalidationexception Data
  Bill
  Bill
  Jun 19, 2019 @ 03:28am

Copy that, thx Rick. Yes, validateRequest is true (the default) for the application so IIS is capturing the request and throwing the error. The Application_Error() method in global.asax does fire, I trap the error there and redirect the User to an error page notifying them of the error and the reason for it ( and a no-no warning ). But I have not found any way in Application_Error() to retrieve the actual text that triggered the error. It all currently works fine but I was hoping to log the actual text that triggered the error for analysis and documentation.

Gravatar is a globally recognized avatar based on your email address. re: httprequestvalidationexception Data
  Rick Strahl
  Bill
  Jun 19, 2019 @ 06:20pm

Are you getting the actual HttpRequestValidationException? I wouldn't expect there to be an inner exception because that's pretty much a top level exception. If you are getting it, then all the information you are getting is all you're going to get I think, but I think you should see the same message that you'd get if there is no Application_Error handling in place (ie. the yellow screen of death that usually tells you the invalid text that's being rejected.).

+++ Rick --

Gravatar is a globally recognized avatar based on your email address. re: httprequestvalidationexception Data
  Bill
  Rick Strahl
  Jun 20, 2019 @ 03:43am

Yes, I trap for the specific httprequestvalidationexception among others in the Application_Error handler. I checked the exception Data array for additional data and there is none. I also check for an InnerException but there is none also. As a result I have just assumed that ASP.NET does not pass the offending text on to the error handler, but wanted to check in case I am missing something.

© 1996-2024