【问题标题】:PlatformNotSupportedException: This operation requires IIS integrated pipeline mode in VS 2015PlatformNotSupportedException:此操作需要 VS 2015 中的 IIS 集成管道模式
【发布时间】:2018-12-04 23:47:20
【问题描述】:

我在尝试使用 Visual Studio 2015 中名为 MvcIntegrationTestFramework 的项目对我的 ASP.NET MVC 项目运行单元测试时遇到此错误。正如我搜索的大多数解决方案建议切换到使用 IIS Express .但我已经在使用 IIS Express。我也可以设置 IIS,但我不想这样做,因为多个开发人员必须在他们的环境中做同样的事情。

其他人建议直接修改 Response.Headers 集合可能会导致此错误,但我没有看到项目中的任何代码可以这样做。

您还有什么其他我可能忽略的可能导致此错误的地方吗?

这是完整的错误和堆栈跟踪...

[PlatformNotSupportedException:此操作需要集成 IIS 管道模式。] System.Web.HttpResponse.get_Headers() +242
Microsoft.Owin.Host.SystemWeb.OwinCallContext.CreateEnvironment() +532 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.GetInitialEnvironment(HttpApplication 申请)+372
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.PrepareInitialContext(HttpApplication 申请)+19
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(对象 发件人,EventArgs e,AsyncCallback cb,对象额外数据)+354
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +673 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +146

【问题讨论】:

标签: asp.net-mvc visual-studio-2015 owin iis-express


【解决方案1】:

我目前正在调查这个问题。到目前为止,我已经学会了:

  • HttpRuntime.UsingIntegratedPipeline 可用于验证 Http 应用程序是否在集成管道中运行(顾名思义)
  • Microsoft.Web.Administration.ApplicationPool.ManagedPipelineMode 属性可用于设置管道模式,但这仅在 IIS 应用程序中运行时有效
  • IntegratedPipelineMode 仅在 HttpApplication 通过 IIS 运行时可用

  • MvcIntegrationTestFramework 启动一个 HttpApplication,但不使用 IIS,所以不能使用 IntegratedPipelineMode

查看 HttpRuntime 的参考来源: https://referencesource.microsoft.com/#system.web/HttpRuntime.cs

这段代码表明 UseIntegratedPipeline 只有在某种 IIS 上下文中运行时才设置为 true。它还表明 _iisVersion 仅在这种情况下填写。

     internal static void PopulateIISVersionInformation() {
        if (IsEngineLoaded) {
            uint dwVersion;
            bool fIsIntegratedMode;
            UnsafeIISMethods.MgdGetIISVersionInformation(out dwVersion, out fIsIntegratedMode);

            if (dwVersion != 0) {
                // High word is the major version; low word is the minor version (this is MAKELONG format)
                _iisVersion = new Version((int)(dwVersion >> 16), (int)(dwVersion & 0xffff));
                _useIntegratedPipeline = fIsIntegratedMode;
            }
        }
    }

我调试到 MvcIntegrationTestFramework 的 BrowsingSession 类。 ProcessRequest 方法将引发异常。在该方法中可以查看 HttpRuntime 的属性:

_iisVersion 为空的事实似乎证明了这一点。

我假设 MvcIntegrationTestFramework “应该被编辑”以在 IIS 中运行 HttpApplication。但该框架的全部意义在于模拟应用程序,因此这样做可能会达不到目的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多