title: MVC [HandleError] HandleErrorAttribute called twice when using global logging
body: <p>In an MVC3 web application I was using</p>
  
  <pre><code>public static void RegisterGlobalFilters(GlobalFilterCollection filters)
  {
      filters.Add(new HandleErrorAttribute());
  }
  </code></pre>
  
  <p>to apply global error handling where the user was shown the 'Error' view if an unhandled exception occured. </p>
  
  <p>For one particular View, I also wanted a different error view to be displayed if an unhandled exception occurred by decorating the method with  <code>[HandleError(View = "SpecialError")]</code>. This worked fine.</p>
  
  <p>I then wanted to add global <em>logging</em> of unhandled exceptions. I created a custom HandleError attribute with logging code:</p>
  
  <pre><code>public class MyHandleErrorAttribute : HandleErrorAttribute
      {
          public override void OnException(ExceptionContext context)
          {
              // Write to log code
              base.OnException(context);
          }
      }
  </code></pre>
  
  <p>And updated RegisterGlobalFilters and method decoration to use this attribute name instead. This works generally but when an exception occurs within the method that is decorated with <code>MyHandleError(View = "SpecialError")]</code> the OnException method is called <em>twice</em>. I originally presumed that decorating the method with this attribute superseded the global handler, but it seems that it is simply added to (which makes more sense, but it isn't what I want). By calling OnException twice, the same exception is logged twice which must not happen. I don't think OnException is being called twice <em>because</em> it is a custom attribute - I believe this happens with the standard HandleError attribute also, it is simply now visible as I am creating a record of it.</p>
  
  <p>Ultimately, I want to log all unhandled exceptions (once), while retaining the features offered by [HandleError], particularly setting different views for particular method exceptions. Is there a clean way of doing this?</p>