title: How to prevent error messages for WebResource.axd errors from appearing in the Application log?
body: <p>I am running an ASP.NET web application under IIS 7.5 and my Application log is full of errors like this:</p>
  
  <blockquote>
    <p>Event code: 3012 </p>
    
    <p>Event message: An error occurred processing a web or script resource
    request. The resource identifier failed to decrypt. </p>
    
    <p>...</p>
    
    <p>Exception information: </p>
  
  <pre><code>Exception type: HttpException 
  
  Exception message: Unable to validate data.
  </code></pre>
    
    <p>at
    System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean
    fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length,
    Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType,
    Boolean signData)</p>
    
    <p>...</p>
    
    <p>Request information: </p>
  
  <pre><code>Request URL: http://www.mysite.com/WebResource.axd?d=l0ngstr1ng0fl3tt3rs4ndd1g1ts 
  
  Request path: /WebResource.axd 
  </code></pre>
    
    <p>...</p>
  </blockquote>
  
  <p>How can I prevent them from appearing?  As per <a href="http://blog.beacontechnologies.com/prevent-errors-from-being-written-to-application-event-log/">this link</a>, I have added the following code to my Global.asax file:</p>
  
  <pre><code>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 &lt;doNastyThings /&gt; tags in the URLs
    if (
      (ex is HttpException &amp;&amp; (path.StartsWith("/WebResource.axd") || path.StartsWith("/ScriptResource.axd"))) ||
      (ex is HttpException &amp;&amp; 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");
    }
  }
  </code></pre>
  
  <p>The second group of errors (for potentially dangerous requests) are being caught and repressed by this code; the WebResource.axd errors have already been written to the Application log by the time this code is executed, however.  I'm presuming that's because the AXD handler works differently to the standard ASPX handler in terms of error logging (but I have no idea what to do as a result).</p>
  
  <p>All help gratefully received!</p>