ASP.NET 4.8,异常消息:当前应用程序配置中不支持 WebSockets

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

我收到有关无法运行 websockets 的错误

Exception information: 
    Exception type: InvalidOperationException 
    Exception message: 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>

奇怪的是,表面上的机器没有 4.0(也不是 4.5),而是运行 4.8,没有硬编码到特定版本(这似乎是他们在错误中建议的)我如何让 IIS 意识到这一点有足够新的版本来完成它需要做的事情吗?

我查看了注册表,可以看到版本显示正确,所以我有点困惑,我的 Google-foo 让我失望了:-)

registry setting

app-pool setting

asp.net iis websocket .net-framework-version
3个回答
0
投票

ASP.NET 4.x运行时有多种兼容模式,以确保旧版应用程序正常运行。但是,如果开发人员弄乱了设置,这可能会成为问题。

我可以通过创建 .NET Framework 4.6 ASP.NET WebForms 项目并添加一些 WebSocket 服务器端代码来重现此问题,只要我通过

<httpRuntime targetFramework="4.0" /> 中的 
web.config
 强制 Web 应用程序在 .NET Framework 4.0 兼容模式下运行
.

如果我设置

<httpRuntime targetFramework="4.5" />
(如异常消息所示)或
<httpRuntime targetFramework="4.6" />
(以匹配实际的项目目标框架版本),则可以解决该问题。

如果您确定您的 Web 应用程序仅在 .NET Framework 4.8 及更高版本上运行,则应将项目文件升级到目标 .NET Framework 4.8,并设置

<httpRuntime targetFramework="4.8" />
以及
<compilation targetFramework="4.8" />
以删除兼容性位。


-1
投票

分配给您的应用程序的应用程序池在 IIS 管理控制台的应用程序池文件夹中显示 NET 版本:

IIS 管理控制台:服务器 - 应用程序池 [1]:https://i.sstatic.net/rUhJP1tk.png


-1
投票

您可以尝试清除缓存并重新启动 IIS,这将清除临时 ASP.NET 文件并重新启动 IIS。

iisreset /stop
del /f /q %windir%\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\* 
iisreset /start
© www.soinside.com 2019 - 2024. All rights reserved.