如何在将 signalR 与 websockets 结合使用时创建在集线器上的每个方法上调用的中间件

How to create a middleware that is invoked on each method on the hub while using signalR with websockets

我正在将 signalR hub 与 Websockets 一起使用,我需要创建一个中间件,它将在 hub 上的每个方法上调用。我曾经使用上下文访问器,但它只有 http 请求,它具有连接到集线器的第一个请求,而不是在集线器上调用的实际方法。

I'm using signalR hub with Websockets and I need to create a middleware that will be invoked on each method on the hub.

ASP.NET Core 5.0 或更高版本中的集线器过滤器与中间件非常相似,它可以帮助 运行 客户端调用集线器方法前后的自定义逻辑。

有关 ASP.NET 核心 SignalR 集线器过滤器的详细信息,请查看此文档:https://docs.microsoft.com/en-us/aspnet/core/signalr/hub-filters?view=aspnetcore-6.0