I'm trying to migrate my old WebSocket server to ASP.NET Core 3.1. Problem is that even minimum example is not working - when connecting server via web socket on debug, no code is executed and websocket connect timeouts.
I just create empty ASP.NET Core 3.1 project from template and add: - app.UseWebSockets(); - app.Use - see code below I also comment out default Routing and UseEndpoints.
Startup code:
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseWebSockets(); app.Use(async (context, next) => { if (context.WebSockets.IsWebSocketRequest) { WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); await Echo(context, webSocket); } else { await context.Response.WriteAsync("Not a websocket request"); //context.Response.StatusCode = 400; } }); //app.UseRouting(); //app.UseEndpoints(endpoints => //{ // endpoints.MapGet("/", async context => // { // //int a = 0; // await context.Response.WriteAsync("Hello World!"); // }); //}); } private async Task Echo(HttpContext context, WebSocket webSocket) { var buffer = new byte[1024 * 4]; WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); while (!result.CloseStatus.HasValue) { await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, result.Count), result.MessageType, result.EndOfMessage, CancellationToken.None); result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None); } await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None); } When I connect to this server via browser/normal http request, I get correct response "Not a websocket request". But when I try to connect via WebSocket, no user code is hit. In ASP .NET Core 2.2 code works.
Do I have to specify somewhere to accept WebSockets?


when I try to connect via WebSocket, no user code is hitBased on my test, WebSockets supports well in .NET Core 3.0. Please share the code snippet you are using to establish connection and exchange message, so that we can troubleshoot the issue better.ws://orwss://?