405 Error for WebSocket with WSS but not WS (ASP.Net)
-
Banging my head on a likely simple problem... I'm getting a 405 on a WebSocket connection with WSS but not WS. Vanilla project in VS with this code. Starting with HTTP works. Starting under HTTPS faults 405. ``` public static class Program { public static void Main (string [] args) { var builder = WebApplication.CreateBuilder ( args ); var app = builder.Build (); app.UseWebSockets (); app.MapGet ( "/" , (HttpContext http) => http.Response.WriteAsync ($$""" self.Socket = new WebSocket(`${location.origin.replace("http", "ws")}/socket`); """ ) ); app.MapGet ( "/socket" , Connect); app.Run (); } static void Connect (HttpContext HttpContext) { _ = HttpContext.WebSockets.AcceptWebSocketAsync ().Result; } } ```
-
Banging my head on a likely simple problem... I'm getting a 405 on a WebSocket connection with WSS but not WS. Vanilla project in VS with this code. Starting with HTTP works. Starting under HTTPS faults 405. ``` public static class Program { public static void Main (string [] args) { var builder = WebApplication.CreateBuilder ( args ); var app = builder.Build (); app.UseWebSockets (); app.MapGet ( "/" , (HttpContext http) => http.Response.WriteAsync ($$""" self.Socket = new WebSocket(`${location.origin.replace("http", "ws")}/socket`); """ ) ); app.MapGet ( "/socket" , Connect); app.Run (); } static void Connect (HttpContext HttpContext) { _ = HttpContext.WebSockets.AcceptWebSocketAsync ().Result; } } ```
If you google "405 error", you get a description of why it occurs: How to Fix HTTP Error 405 Method Not Allowed: 11 Methods[^] But the most likely reason is simple: the remote site does not support HTTPS - so HTTP requests succeed, but secure ones fail. The only cure for that would be to contact the remote admins, and ask them to support HTTPS (which will require a valid certificate). Investigating that is where I'd start.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
If you google "405 error", you get a description of why it occurs: How to Fix HTTP Error 405 Method Not Allowed: 11 Methods[^] But the most likely reason is simple: the remote site does not support HTTPS - so HTTP requests succeed, but secure ones fail. The only cure for that would be to contact the remote admins, and ask them to support HTTPS (which will require a valid certificate). Investigating that is where I'd start.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
This is all in my own environment and https works on the site/server but not with sockets (wss). This is (basically) code that I had running fine on .Net6, so I'm thinking there could be a config setting. I discovered it when I started upgrading (to `WebApplication`) some old (working) apps. It also works (WSS) when I'm running Fidder. If I close Fiddler, it quits working.
-
If you google "405 error", you get a description of why it occurs: How to Fix HTTP Error 405 Method Not Allowed: 11 Methods[^] But the most likely reason is simple: the remote site does not support HTTPS - so HTTP requests succeed, but secure ones fail. The only cure for that would be to contact the remote admins, and ask them to support HTTPS (which will require a valid certificate). Investigating that is where I'd start.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
OriginalGriff wrote:
does not support HTTPS - so HTTP requests succeed, but secure ones fail.
I don't think so. The 405 is a HTTP error. So the HTTP server is responding to the request with that error. The 'S' means that the protocol is actually HTTP (and thus TCP) with SSL (or perhaps TLS) in place. The SSL protocol runs on the TCP layer and not the HTTP layer. If SSL is not in place (TCP) then for client server two things can happen 1. The client expects SSL but server is not doing it: Then it results in a timeout in the connection for the client because the client is expecting a response (the SSL protocol) which never happens. 2. The client is not using SSL but the server is: In this case the server ends up closing the socket because the the client never sent the expected SSL protocol messages. Client sees error message along the lines of the 'remote end' closed the socket. But it will not show up until the client attempts to use the socket (so connection worked but then later usage fails.)
-
Banging my head on a likely simple problem... I'm getting a 405 on a WebSocket connection with WSS but not WS. Vanilla project in VS with this code. Starting with HTTP works. Starting under HTTPS faults 405. ``` public static class Program { public static void Main (string [] args) { var builder = WebApplication.CreateBuilder ( args ); var app = builder.Build (); app.UseWebSockets (); app.MapGet ( "/" , (HttpContext http) => http.Response.WriteAsync ($$""" self.Socket = new WebSocket(`${location.origin.replace("http", "ws")}/socket`); """ ) ); app.MapGet ( "/socket" , Connect); app.Run (); } static void Connect (HttpContext HttpContext) { _ = HttpContext.WebSockets.AcceptWebSocketAsync ().Result; } } ```