How to prevent error messages for WebResource.axd from appearing in the application log?

I am running an ASP.NET web application in IIS 7.5, and the application log is filled with the following errors:

Event ID: 3012

Event message: An error occurred while processing the web resource or script request resource. Resource ID could not be decrypted.

...

Exception Information:

Exception type: HttpException Exception message: Unable to validate data. 

in System.Web.Configuration.MachineKeySection.EncryptOrDecryptData (Boolean fEncrypt, Byte [] buf, Byte [] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType ivType ivType signType

...

Request information:

 Request URL: http://www.mysite.com/WebResource.axd?d=l0ngstr1ng0fl3tt3rs4ndd1g1ts Request path: /WebResource.axd 

...

How can I stop them from appearing? From this link , I added the following code to the Global.asax file:

 void Application_Error(object sender, EventArgs e) { // Code that runs when an *unhandled* error occurs //// get reference to the source of the exception chain Exception ex = Server.GetLastError(); string message = ex.Message; string path = Request.Path; // ignore the following: // errors due to bots trying AXD URLs // errors due to <doNastyThings /> tags in the URLs if ( (ex is HttpException && (path.StartsWith("/WebResource.axd") || path.StartsWith("/ScriptResource.axd"))) || (ex is HttpException && message.StartsWith("A potentially dangerous Request.Path value was detected from the client")) ) { // clear the error *to prevent it from appearing in the main Application log* Server.ClearError(); // need to manually direct to the error page, since it will no longer happen automatically once the error has been cleared Response.Redirect("/Error"); } } 

The second group of errors (for potentially dangerous queries) is captured and suppressed by this code; however, WebResource.axd errors are already written to the application log by the time this code is run. I assume that since the AXD handler works differently with the standard ASPX handler in terms of error reporting (but I don’t know what to do as a result).

All help was gratefully received!

+6
source share
3 answers

I get this error only when I receive requests from the Bingbot crawler. You can check if this is a bing bot here

So I added this to my robots.txt file. This does not work unless you specifically add that it is a Bingbot user agent

 User-agent: bingbot Disallow: /ScriptResource.axd Disallow: /combinescriptshandler.axd Disallow: /WebResource.axd 
+8
source

/WebResource.axd is usually requested because the page contains a link to it, often img src:

 <img ... src="/WebResource.axd..." /> 

usually generated from ASP.NET WebControl, for example. menu control.

I would recommend that you find the page containing the WebResource.axd link, see how and why it is created, and why it is invalid. For example, you can look at the IIS server logs to find which page immediately precedes the WebResource.axd request, or you can add your own log to Application_BeginRequest.

Once you recognize the abusive page and determine which control on the page generates the request, ask again here.

I saw this in the past on a static HTML page containing HTML (like a menu) that was copied and pasted from the displayed ASPX page. The request is invalid on a static HTML page, and the fix was just to remove the abusive img element.

+2
source

These errors can be caused when Bingbot does something really stupid and reduces the requested URL.

I don’t know why this is happening, but the URL specified in the event log is actually associated with the affected page - only with capital letters! For example, the actual link in HTML:

 https://example.com/WebResource.axd?d=[...]13QzJRP4goegQTwpQQcl[...] 

Same link as bingbot request:

 https://example.com/WebResource.axd?d=[...]13QzJRP4goegQTwpQQcl[...] 

Well, these are clearly harmless errors that need to be ignored or suppressed.

+2
source

Source: https://habr.com/ru/post/956486/


All Articles