【发布时间】:2018-08-30 16:08:19
【问题描述】:
我们有一个常规的 asp.net Web 应用程序,并添加了基于 Owin 的 OpenID Connect 身份验证 (AzureAD)。在我的 IIS Express 上的本地计算机上,Owin 启动根本没有被触发,即使 Microsoft.Owin.Host.SystemWeb dll 在那里,我们也尝试过设置就像owin:AutomaticAppStartup 和owin:appStartup 一样,没有任何改变。
使 Owin 在本地工作的唯一解决方案是通过调用 Microsoft.Owin.Host.SystemWeb.PreApplicationStart.Initialize();
当我们在 IIS 上部署到 Azure(云服务,我们可以访问托管 VM)时,应用在 webrole 的 OnStart 期间抛出以下堆栈跟踪:
[InvalidOperationException]: Operation is not valid due to the current state of the object.
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.PushLastObjects(IDictionary`2 environment, TaskCompletionSource`1 completionSource)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.Epilog(IDictionary`2 env)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.DefaultAppInvoked(IDictionary`2 env)
at Microsoft.Owin.Mapping.MapMiddleware.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.<Invoke>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->
有没有人知道什么地方以及什么可能导致问题?我对 Owin 内部结构以及管道的初始化方式没有深入了解,因此我不确定基于此跟踪是在应用程序启动时还是在实际请求期间,但因为它不包含我们实现的任何代码我想它在启动时会失败。也许在常规 IIS 上 Owin 确实正常启动,不像 IIS Express 中那样,而 Global.asax 中的额外调用导致了这个奇怪的异常?
【问题讨论】: