[英]ASP.NET Core WebSockets on IIS 7.5
I know the WebSockets are supported only on Windows 8 and higher. 我知道WebSocket仅在Windows 8和更高版本上受支持。 But sometimes you just can't upgrade the system in large organization.
但是有时您无法在大型组织中升级系统。 So I tried implement WebSockets on ASP.NET Core app.
因此,我尝试在ASP.NET Core应用上实现WebSockets。 I take NuGet package "AspNetCore.WebSockets.Server" and run as a self-hosted app on Windows 7 and everything works well.
我拿了NuGet软件包“ AspNetCore.WebSockets.Server”,并在Windows 7上作为自托管应用程序运行,并且一切正常。 But hosting on IIS7.5 on the same machine wont allow me to upgrade HTTP connection to WebSocket.
但是在同一台计算机上的IIS7.5上托管,将不允许我将HTTP连接升级到WebSocket。 Even if I try to simulate the handshake the IIS simple removes my "Sec-WebSocket-Accept" header.
即使我尝试模拟握手,IIS也会简单地删除“ Sec-WebSocket-Accept”标头。
static async Task Acceptor(HttpContext hc, Func<Task> next)
{
StringValues secWebSocketKey;
if(hc.Request.Headers.TryGetValue("Sec-WebSocket-Key", out secWebSocketKey))
{
hc.Response.StatusCode = 101;
hc.Response.Headers.Clear();
hc.Response.Headers.Add("Upgrade", new StringValues("websocket"));
hc.Response.Headers.Add("Connection", new StringValues("Upgrade"));
// Disappears on client
hc.Response.Headers.Add("Sec-WebSocket-Accept", new StringValues(GetSecWebSocketAccept(secWebSocketKey[0])));
}
await next();
}
I definitely sure IIS7.5 physically can manage WebSockets if they was implemented by developer and that behavior (header removal) looks like a dirty trick from Microsoft 我绝对确定,如果开发人员实现了IIS7.5,则IIS7.5在物理上可以管理WebSocket,并且该行为(标题删除)看起来像是Microsoft的恶作剧
I am afraid you need IIS 8 恐怕您需要IIS 8
With the release of Windows Server 2012 and Windows 8, Internet Information Services (IIS) 8.0 has added support for the WebSocket Protocol.
随着Windows Server 2012和Windows 8的发布,Internet Information Services(IIS)8.0添加了对WebSocket协议的支持。
https://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support https://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support
The new http.sys is the one that can turn a regular HTTP connection into a binary communication for websockets. 新的http.sys可以将常规HTTP连接转换为websocket的二进制通信。 Although you can implement your own thing, you cannot hook it into http.sys.
尽管您可以实现自己的东西,但是不能将其挂接到http.sys中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.