.net 如何在执行WebDeploy时防止失败的请求?

.net 如何在执行WebDeploy时防止失败的请求?,.net,webdeploy,owin,asp.net-web-api2,.net,Webdeploy,Owin,Asp.net Web Api2,我通过OWIN启动类在IIS安装程序上运行WebApi。从VisualStudio部署后,有几个请求总是失败。这扇窗户只能开几秒钟。从那以后一切都好了 我有这样的例外情况: System.ArgumentException: The 'DelegatingHandler' list is invalid because the property 'InnerHandler' of 'CorsMessageHandler' is not null. Parameter name: handlers

我通过OWIN启动类在IIS安装程序上运行WebApi。从VisualStudio部署后,有几个请求总是失败。这扇窗户只能开几秒钟。从那以后一切都好了

我有这样的例外情况:

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.<EnsureInitialized>b__b()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at System.Web.Http.HttpServer.EnsureInitialized()
   at System.Web.Http.HttpServer.<SendAsync>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.<InvokeCore>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& completedSynchronously)
System.ArgumentException:“DelegatingHandler”列表无效,因为“CorsMessageHandler”的属性“InnerHandler”不为null。
参数名称:处理程序
位于System.Net.Http.HttpClientFactory.CreatePipeline(HttpMessageHandler innerHandler,IEnumerable`1处理程序)
在System.Web.Http.HttpServer.Initialize()中
在System.Web.Http.HttpServer.b__b()上
在System.Threading.LazyInitializer.EnsureInitializedCore[T](T&target,Boolean&initialized,Object&syncLock,Func`1 valueFactory)
在System.Web.Http.HttpServer.EnsureInitialized()上
在System.Web.Http.HttpServer.d_u0.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在System.Web.Http.Owin.HttpMessageHandlerAdapter.d_u0.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
位于Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
在System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()中
在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)
或:

System.ObjectDisposedException:无法访问已处置的对象。
对象名称:“System.Web.Http.HttpServer”。
在System.Net.Http.DelegatingHandler.set_InnerHandler(HttpMessageHandler值)处
在System.Web.Http.HttpServer.b__b()上
在System.Threading.LazyInitializer.EnsureInitializedCore[T](T&target,Boolean&initialized,Object&syncLock,Func`1 valueFactory)
在System.Web.Http.HttpServer.EnsureInitialized()上
在System.Web.Http.HttpServer.d_u0.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在System.Web.Http.Owin.HttpMessageHandlerAdapter.d_u0.MoveNext()中
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
位于Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
在System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()中
在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)
我将这些从HttpApplicationContext.Error事件处理程序记录在IHttpModule.Init中。他们无法访问WebApi的IEExceptionLogger。这些发生在我的启动已经运行之后(出现在这些异常之前的日志中)

我希望在部署时尽量减少失败请求的数量


我从哪里开始?

如果部署期间不能容忍任何BLISH,您可能需要考虑“蓝色/绿色部署”方法:

在您的IIS站点下有两个独立的应用程序—一个用于当前正在生产的应用程序,另一个用于通过WebDeploy推送的登台/平台构建。WebDeploy成功后,您可以将生产IIS应用程序指向此新文件夹。旧文件夹现在是一个短期备份,如果发生任何问题,您可以将其翻转回去,然后可以重新用作下一次部署的暂存/平台

当然,您可以将其自动化更多,但这是基本思想

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.<EnsureInitialized>b__b()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at System.Web.Http.HttpServer.EnsureInitialized()
   at System.Web.Http.HttpServer.<SendAsync>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.<InvokeCore>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& completedSynchronously)