ASP.NET MVC 应用程序中的 httpRuntime targetFramework 问题

问题描述 投票:0回答:1

当前正在尝试在我的 ASP.NET MVC 应用程序中实现 SignalR。当我指定我希望它在客户端中使用 Web 套接字时,如下所示:

 $.connection.hub.start({ transport: ['webSockets'] })
        .then(init)
        .then(function() {
            console.log('Hub Started Successfully!');
        });

我收到一条错误消息,指出不支持 Web 套接字,我需要将以下行添加到我的配置文件中:

<httpRuntime targetFramework="4.5.1" />

这是确切的错误:

 WebSockets is unsupported in the current application configuration. To
 enable this, set the following configuration switch in Web.config:
 <system.web>  
    <httpRuntime targetFramework="4.5" /> 
 </system.web>

当我这样做时,我的部分视图的异步等待停止工作,并且出现以下错误:

InvalidOperationException:HttpServerUtility.Execute 被阻止 等待异步操作完成。

当我从配置文件中删除运行时目标框架行时,不会发生此错误。

ASP.NET MVC 项目在 .NET 4.7.1 框架上运行,服务器/本地开发机器上安装了 4.0 的运行时。

任何帮助将不胜感激。预先感谢您!

asp.net-mvc websocket httpruntime
1个回答
0
投票

有趣的是我回来给出答案。

您需要设置

<httpRuntime targetFramework="4.7.1" />
以匹配您的实际项目目标框架版本,而不是任何旧版本。

ASP.NET运行时兼容模式非常复杂。所以,

  • WebSockets 支持需要 4.5 及更高版本,因此如果不匹配,您会收到“当前应用程序配置中不支持 WebSockets”。
  • 部分视图中的async/await需要更高版本,因此当您设置4.5.1时,它会触发“InvalidOperationException:HttpServerUtility.Execute被阻止”。

只有当您设置的值与编译目标版本以及项目目标版本匹配时,所有兼容模式都会消失,一切都会开始按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.