401 Unauthorized meme

How to secure your WebSocket connection using .NET Core?

This article explains how to easily authenticate your WebSocket connections using .NET Core and vanilla JavaScript. The same concept probably applies to all sorts of front-end libraries, although some of them might offer some syntactic sugar on top of it. But it’s simple, and keeping your implementation simple is generally speaking a good idea. So – this one came up when developing a simple API that’d expose a WebSocket endpoint for seamless notifications to the Web UI. As everything else in the system required authentication,…Continue reading How to secure your WebSocket connection using .NET Core?

WebSockets.

HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core?

This article explains another simple fix to an annoying issue. I guess that’s how I start like every other one of my little tutorials, but hey, it’s true! I suppose I just have a knack for running into issues that come with poorly documented fixes or workarounds that are obvious but only in hindsight… Right? Anyway, this time my WebSocket requests were not being handled as such by my ASP.NET Controllers. “IsWebSocketRequest” was suggested by IntelliSense, but it would always be null in the code.…Continue reading HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core?

WebSockets.

How to test a WebSocket connection in a browser

This article documents a simple and neat way to establish and test a WebSocket connection, using just vanilla JavaScript and your favorite browser’s developer tools. Quick and easy – no external tools or libraries required! In the sample I’ll show just a few paragraphs below, we’ll instantiate a websocket connection, hook a listener to the onmessage event and the last line sends a simple payload down the WebSocket pipe, just to see if something happens. If there IS a response, we’ll be logging it in…Continue reading How to test a WebSocket connection in a browser