Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 405 Error for WebSocket with WSS but not WS (ASP.Net)

405 Error for WebSocket with WSS but not WS (ASP.Net)

Scheduled Pinned Locked Moved C#
helpcsharpasp-netvisual-studio
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gwyll
    wrote on last edited by
    #1

    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; } } ```

    OriginalGriffO G 2 Replies Last reply
    0
    • G Gwyll

      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; } } ```

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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!

      "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

      G J 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        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!

        G Offline
        G Offline
        Gwyll
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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!

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          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.)

          1 Reply Last reply
          0
          • G Gwyll

            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; } } ```

            G Offline
            G Offline
            Gwyll
            wrote on last edited by
            #5

            I think I'm getting closer. I found a change in Edge that says it no longer uses the Windows certs - but manages its own. It doesn't seem to pick up my/VS self-gen'ed dev cert. Going to try to figure out how to do a manual import and see if that helps.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups