【问题标题】:How to prevent failed requests when performing WebDeploy?执行 WebDeploy 时如何防止失败的请求?
【发布时间】:2014-04-23 06:32:24
【问题描述】:

我有一个通过 OWIN 启动类在 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 已经运行之后(出现在这些异常之前的日志中)。

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

我从哪里开始?

【问题讨论】:

    标签: .net webdeploy owin asp.net-web-api2


    【解决方案1】:

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

    在您的 IIS 站点下有 2 个单独的应用程序 - 一个用于当前生产中的应用程序,一个用于您通过 WebDeploy 推送的登台/现场构建。一旦 WebDeploy 成功,您可以将您的生产 IIS 应用程序指向这个新文件夹。旧文件夹现在是一个短期备份,如果发生任何故障,您可以返回到该文件夹​​,并且以后可以重新用作下一次部署的登台/甲板上。

    当然,您可以进一步自动化,但这是基本思想。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多