aspnetcore: Using SignalR Clients.All.SendAsync in a registered Middlware without disconnecting when making a request to trigger middleware.
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have a middleware that looks like this. Logs all requests coming into an application into MongoDB for historical data purposes. I want to push these new logs to a SignalR Hub to all clients connected before it is saved to MongoDB. SignalR gets disconnected when doing a Clients.All.SendAsync in a middleware in a NET Core 3.1 when making a post request.

Is it possible to use SignalR like this in a middleware as opposed to the same functionality over and over directly in the controller? Or am I missing a detail of the Request Pipeline when using Middleware that is causing the websocket connnection to disconnect within the middleware?
Expected Behavior

Same behavior of pushing the data to all clients if I was to register this class as a Singleton and use it above this method or any method in a Controller.

Steps To Reproduce
Create a SignalR Hub. Connect to Hub via React or Angular. Send to all client connected to hub in Middleware that shown above.
Exceptions (if any)
N/A
.NET Version
7.0.100-rc.2.22477.23
Anything else?
.NET Core 3.1 issue.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (10 by maintainers)
I have never had the need to write one, will look into it tomorrow. I also found the Discord channels. Thanks for the community. I am in-between an offer and interviewing ATM. 😃