0

I know the WebSockets are supported only on Windows 8 and higher. But sometimes you just can't upgrade the system in large organization. So I tried implement WebSockets on ASP.NET Core app. I take NuGet package "AspNetCore.WebSockets.Server" and run as a self-hosted app on Windows 7 and everything works well. But hosting on IIS7.5 on the same machine wont allow me to upgrade HTTP connection to WebSocket. Even if I try to simulate the handshake the IIS simple removes my "Sec-WebSocket-Accept" header.

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

1 Answer 1

1

I am afraid you need 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.

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. Although you can implement your own thing, you cannot hook it into http.sys.

Not the answer you're looking for? Browse other questions tagged or ask your own question.