title: Application Insights and failed request response codes
body: <p>When an exception is unhandled in our web API, a response code 500 (Internal Server Error) will return to the client.</p>
  
  <p>Although Application Insights doesn't record this as a 500, but rather a 200.  <code>Successful request</code> is <code>false</code>, but the response code is still wrong.</p>
  
  <p><a href="https://i.stack.imgur.com/bag3S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bag3S.png" alt="Application Insights failed request"></a></p>
  
  <p>How can I get the corrrect response codes in my telemetry?</p>
  
  <p>Startup's <code>Configure</code>:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment environment)
  {
      if (!TelemetryConfiguration.Active.DisableTelemetry)
      {
          // Add Application Insights to the beginning of the request pipeline to track HTTP request telemetry.
          app.UseApplicationInsightsRequestTelemetry();
  
          // Add Application Insights exceptions handling to the request pipeline. Should be
          // configured after all error handling middleware in the request pipeline.
          app.UseApplicationInsightsExceptionTelemetry();
      }
  
      app.UseRequireHttps(environment.IsLocal());
      app.UseMiddleware&lt;NoCacheMiddleware&gt;();
      app.UseJwtBearerAuthentication(...);
      app.UseCors("CorsPolicy");
      app.UseStaticFiles();
      app.UseCompression();
      app.UseMvc();
  }
  </code></pre>