title: Why MessageHandler is executing in MVC request?
body: <p>I have a project include MVC and Web API controllers. I have,</p>
  
  <pre><code> GlobalConfiguration.MessageHandlers.Insert(0, new MessageHandler1());
  </code></pre>
  
  <p>But when I request a MVC controller it executes this handler. It hurting me because SuppressDefaultHostAuthentication is executing PassiveAuthenticationMessageHandler handler on MVC request. I have put a break-point on MessageHandler1.SendAsync and found that System.Web.HttpContext.Current.Handler = {System.Web.Mvc.MvcHandler} which confirm that it is MVC request.  </p>
  
  <p>StackTrace,</p>
  
  <pre><code>MyApp.dll!MyApp.MessageHandler1.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Line 120    C#
      System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)   Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.AnonymousMethod__FabricatedMethod5()   Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync.AnonymousMethod__0() Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync&lt;System.Net.Http.HttpResponseMessage&gt;(System.Web.Http.Tracing.ITraceWriter traceWriter, System.Net.Http.HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, string operatorName, string operationName, System.Action&lt;System.Web.Http.Tracing.TraceRecord&gt; beginTrace, System.Func&lt;System.Threading.Tasks.Task&lt;System.Net.Http.HttpResponseMessage&gt;&gt; execute, System.Action&lt;System.Web.Http.Tracing.TraceRecord,System.Net.Http.HttpResponseMessage&gt; endTrace, System.Action&lt;System.Web.Http.Tracing.TraceRecord&gt; errorTrace)    Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.MessageHandlerTracer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)    Unknown
      System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)   Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.AnonymousMethod__FabricatedMethod6()    Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync.AnonymousMethod__1()  Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync&lt;System.Net.Http.HttpResponseMessage&gt;(System.Web.Http.Tracing.ITraceWriter traceWriter, System.Net.Http.HttpRequestMessage request, string category, System.Web.Http.Tracing.TraceLevel level, string operatorName, string operationName, System.Action&lt;System.Web.Http.Tracing.TraceRecord&gt; beginTrace, System.Func&lt;System.Threading.Tasks.Task&lt;System.Net.Http.HttpResponseMessage&gt;&gt; execute, System.Action&lt;System.Web.Http.Tracing.TraceRecord,System.Net.Http.HttpResponseMessage&gt; endTrace, System.Action&lt;System.Web.Http.Tracing.TraceRecord&gt; errorTrace)    Unknown
      System.Web.Http.dll!System.Web.Http.Tracing.Tracers.RequestMessageHandlerTracer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) Unknown
      System.Net.Http.dll!System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)   Unknown
      System.Web.Http.dll!System.Web.Http.HttpServer.AnonymousMethod__FabricatedMethod9() Unknown
      System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync()  Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start&lt;System.Web.Http.HttpServer.SendAsync&gt;(ref System.Web.Http.HttpServer.SendAsync stateMachine)  Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.__Canon&gt;.Start&lt;System.Web.Http.HttpServer.SendAsync&gt;(ref System.Web.Http.HttpServer.SendAsync stateMachine)  Unknown
      System.Web.Http.dll!System.Web.Http.HttpServer.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)  Unknown
      System.Net.Http.dll!System.Net.Http.HttpMessageInvoker.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)  Unknown
      System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore()    Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start&lt;System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore&gt;(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore stateMachine)    Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start&lt;System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore&gt;(ref System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore stateMachine)    Unknown
      System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.InvokeCore(Microsoft.Owin.IOwinContext context, Microsoft.Owin.IOwinRequest owinRequest, Microsoft.Owin.IOwinResponse owinResponse) Unknown
      System.Web.Http.Owin.dll!System.Web.Http.Owin.HttpMessageHandlerAdapter.Invoke(Microsoft.Owin.IOwinContext context) Unknown
      Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke()  Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke stateMachine)  Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke stateMachine)   Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke stateMachine)  Unknown
      Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions&gt;.Invoke(Microsoft.Owin.IOwinContext context)   Unknown
      Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke()    Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke stateMachine)  Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder&lt;System.Threading.Tasks.VoidTaskResult&gt;.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke stateMachine)   Unknown
      mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start&lt;Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke&gt;(ref Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke stateMachine)  Unknown
      Microsoft.Owin.Security.dll!Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware&lt;Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions&gt;.Invoke(Microsoft.Owin.IOwinContext context) Unknown
      Microsoft.Owin.dll!Microsoft.Owin.Infrastructure.OwinMiddlewareTransition.Invoke(System.Collections.Generic.IDictionary&lt;string,object&gt; environment) Unknown
      Microsoft.Owin.Host.SystemWeb.dll!Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(object sender, System.EventArgs e, System.AsyncCallback cb, object extradata)  Unknown
      System.Web.dll!System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   Unknown
      System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously)  Unknown
      System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error)   Unknown
      System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb)  Unknown
      System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr, System.Web.HttpContext context)    Unknown
      System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
      System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags)   Unknown
      [Native to Managed Transition]  
      [Managed to Native Transition]  
      System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) Unknown
      System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr rootedObjectsPointer, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags)   Unknown
      [AppDomain Transition]  
  </code></pre>