I have a web socket server hosted in ASPNET Core RC2. It works fine on my local dev box, when running on just kestrel, and also when kestrel is hosted in IIS. When Google Chrome is used to connect to the websocket server, it works OK on local box, and on remote box:
JavaScript:
new WebSocket("wss://myServer:8087")
However when the JavaScript is connecting to the same server, hosted on our build machine (OS: Server 2008 R2) the client gets this 302 (redirect) error:
WebSocket connection to 'wss://myBuildServer:8087/' failed: Error during WebSocket handshake: Unexpected response code: 302
note: when the JavaScript is running on Chrome on the server itself, the error is different:
WebSocket connection to 'wss://xxx:8087/' failed: WebSocket opening handshake was canceled
C# source that adds web sockets (Microsoft.AspNetCore.WebSockets.Server 0.1.0-rc2-final):
private void ConfigureWebSockets(IApplicationBuilder app)
{
DPT2.Web.Utils.Logger.Log("ConfigureWebSockets()");
_socketHandler = new Sockets.WebSocketHandler(_nodeServices);
app.UseWebSockets(new WebSocketOptions{
//try to fix 302 redirect on build m/c:
ReplaceFeature = true,
//TODO tune via these params:
KeepAliveInterval = TimeSpan.FromMinutes(2),
ReceiveBufferSize = 4 * 1024
});
app.Use(async (http, next) =>
{
if (http.WebSockets.IsWebSocketRequest)
{
var webSocket = await http.WebSockets.AcceptWebSocketAsync();
if (webSocket != null && webSocket.State == WebSocketState.Open)
{
await _socketHandler.Handle(webSocket);
}
}
else
{
// Nothing to do here, pass downstream.
await next();
}
});
}
It looks like the request is being 'corrupted' somehow, and this C# line does not recognise it as a web socket request, and so passes it on to MVC:
if (http.WebSockets.IsWebSocketRequest)
versions:
Server OS: Windows 2008 R2
IIS 6.1 build 7601 - SP1
IIS Manager 7.5.7600.16385
installed the ASPNET Core hosting: DotNetCore.1.0.0.RC2-WindowsHosting.exe
I've tried a few workarounds:
using http for the site, and ws:// for the web socket URL
using https for the site, and wss:// for the web socket URL
adding the ReplaceFeature option to the websocket server
Has anyone else seen a similar issue ?
I think its to do with IIS acting as a reverse proxy for kestrel, and perhaps on that particular machine, the proxying is messing up the web socket request ...
It could be a configuration issue on the server ...
Sean