title: How to prevent failed requests when performing WebDeploy?
body: <p>I have a WebApi running on IIS setup via OWIN Startup class. After I deploy from Visual Studio several requests always fail. This windows only lasts for couple of senconds. Everything is fine after that.</p>
  
  <p>I get exceptions like these:</p>
  
  <pre><code>System.ArgumentException: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'CorsMessageHandler' is not null.
  Parameter name: handlers
     at System.Net.Http.HttpClientFactory.CreatePipeline(HttpMessageHandler innerHandler, IEnumerable`1 handlers)
     at System.Web.Http.HttpServer.Initialize()
     at System.Web.Http.HttpServer.&lt;EnsureInitialized&gt;b__b()
     at System.Threading.LazyInitializer.EnsureInitializedCore[T](T&amp; target, Boolean&amp; initialized, Object&amp; syncLock, Func`1 valueFactory)
     at System.Web.Http.HttpServer.EnsureInitialized()
     at System.Web.Http.HttpServer.&lt;SendAsync&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at System.Web.Http.Owin.HttpMessageHandlerAdapter.&lt;InvokeCore&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
     at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>System.ObjectDisposedException: Cannot access a disposed object.
  Object name: 'System.Web.Http.HttpServer'.
     at System.Net.Http.DelegatingHandler.set_InnerHandler(HttpMessageHandler value)
     at System.Web.Http.HttpServer.&lt;EnsureInitialized&gt;b__b()
     at System.Threading.LazyInitializer.EnsureInitializedCore[T](T&amp; target, Boolean&amp; initialized, Object&amp; syncLock, Func`1 valueFactory)
     at System.Web.Http.HttpServer.EnsureInitialized()
     at System.Web.Http.HttpServer.&lt;SendAsync&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at System.Web.Http.Owin.HttpMessageHandlerAdapter.&lt;InvokeCore&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
     at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>I log these from HttpApplicationContext.Error event handler in a IHttpModule.Init. They don't reach WebApi's IExceptionLogger. These happen after my Startup has already run (appears in log before these exceptions).</p>
  
  <p>I looking to minimize the number of failed requests when deploying.</p>
  
  <p>Where do I start?</p>