title: ASP.NET MVC Application_Error handler in Global.asax
body: <p>In Global.asax we have a class of type System.Web.HttpApplication named MvcApplication
  that represents the application and in which we can handle various events.</p>
  
  <p>I'm interested in the Application_Error handler.
  In this handler we can use all the properties of the class MvcApplication.</p>
  
  <p>-1-</p>
  
  <p>Is always true that '(MvcApplication)sender' and 'this' are the same object?</p>
  
  <pre><code>protected void Application_Error(object sender, EventArgs e)
  {
    var httpApp = (MvcApplication)sender;
    var equality1 = httpApp == this; // always true?
  }
  </code></pre>
  
  <p>-2-</p>
  
  <p>What is the best way to get the error?
  The following examples return the same error?</p>
  
  <pre><code>Exception ex0 = this.Context.Error;
  Exception ex1 = httpContext.Error;
  Exception ex2 = Server.GetLastError();
  var equality3 = ex1 == ex2; // true?
  </code></pre>