我通过OWIN Startup类在IIS设置上运行WebApi。从Visual Studio部署后,多个请求总是失败。这个窗口只持续几秒钟。之后一切都很好。
我得到这样的例外:
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.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)
我从IHttpModule.Init中的HttpApplicationContext.Error事件处理程序中记录这些。他们无法访问WebApi的IExceptionLogger。这些发生在我的Startup已经运行之后(在这些异常之前出现在日志中)。
我希望在部署时尽量减少失败请求的数量。
我从哪里开始?
答案 0 :(得分:0)
如果您在部署期间无法容忍任何昙花一现,您可能需要考虑“蓝/绿部署”方法:
在IIS站点下有两个独立的应用程序 - 一个用于当前正在生产的应用程序,另一个用于通过WebDeploy推送的登台/甲板上构建。 WebDeploy成功完成后,您可以将生产IIS应用程序指向此新文件夹。旧文件夹现在是一个短期备份,如果发生任何事情,您可以将其翻转回来,以后可以重新用作下一次部署的登台/登台。
当然,你可以更自动化这一点,但这是基本的想法。