title: HTTPError Exception Message not displaying when webapi is run on Server vs being run locally
body: <p>I have a webapi that runs on an IIS7.5 server.  It has 3 controllers, and all 3 can be used to access the webapi from calls within my application.</p>
  
  <p>I had a error where my base class for my controller was exposing it's functions as public, rather than protected.  This caused the server to throw an Internal Server Error 500 (because of an invalid exception thrown "Multiple actions were found that match the request").  It took me a while to drill down on this, because it never triggered the logging from my webapi.  From this dicussion <a href="https://stackoverflow.com/questions/11474076/exception-handling-beyond-exception-filters"><strong>here</strong></a>, I discovered that the error that was happening was happening before an Application_Error function would catch it to log it.  So I added the below code to my global.asax of my webapi, and I can now log errors like this.</p>
  
  <p>BUT, my problem now, when I cause an Internal Server Error 500 exactly like above, on my local machine running my webapi, I get a log exactly how I wish to see it with the "ExceptionMessage" of "Multiple actions were found that match the request" spelled out as the reason for the Internal Server Error.  But when deploy this exact code to the server, and use the webapi from there, my log only displays "Message" : "An error has occurred" and does not show me the "ExceptionMessage", even though I can see that the exception is being thrown using PerfView.  I just need to be able to get my server logs to show the same information as what my local log displays.</p>
  
  <pre><code>public class ResponseExceptionTrapper : DelegatingHandler
  {
      protected override Task&lt;HttpResponseMessage&gt; SendAsync(
          HttpRequestMessage request,
          CancellationToken cancellationToken)
      {
          return base
              .SendAsync(request, cancellationToken)
              .ContinueWith(response =&gt;
              {
                  var result = response.Result;
                  if (!result.IsSuccessStatusCode)
                  {
                      var exceptionResult = string.Format(
                           "Response exception: \r\n Path({0}) \r\n Status({1}) \r\n",
                           request.RequestUri,
                           result.StatusCode);
  
                      if (result.Content != null)
                      {
                          var exceptionReadTask =
                                 result.Content.ReadAsStringAsync();
  
                          exceptionReadTask.Wait();
                          exceptionResult += "Message:" +
                                            exceptionReadTask.Result;
  
                      }
  
                      // Do something appropriate with exceptionResult
                      exceptionResult.Log();
                  }
  
                  return result;
              }, cancellationToken);
      }
  }
  </code></pre>
  
  <p>Server Log Example:</p>
  
  <pre><code>Timestamp: 4/24/2014 12:24:40 PM
  Message: Timestamp: 4/24/2014 4:24:40 PM
  Message: Response exception: 
  Path(http://webserver/CreditReporting/Api/RetrieveQueuedPullCreditReport) 
  Status(InternalServerError) 
  Message:{"Message":"An error has occurred."}
  </code></pre>
  
  <p>Local Log Example:</p>
  
  <pre><code>Timestamp: 4/24/2014 12:03:16 PM
  Message: Timestamp: 4/24/2014 4:03:16 PM
  Message: Response exception: 
   Path(http://localhost:XXXXX/Api/RetrieveQueuedPullCreditReport) 
   Status(InternalServerError)
   Message:
    {"Message":"An error has occurred.",
    "ExceptionMessage":"Multiple actions were found that match the request:
      \r\nSystem.Threading.Tasks.Task`1[
   Our.WebServices.CreditReporting.Contracts.RetrieveQueuedPullCreditReportResponse] Post
  </code></pre>