在旧版本的 SignalR 和 .NetFreamwork 中,我使用的类继承了 HubPipelineModule 类,如:
public class IsConnectedPipeLine : HubPipelineModule
{
protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
{
if (context.MethodDescriptor.Name == "GetToken")
return true;
return ChatIdentity.CheckToken(context.Hub.Context.GetCurrentUserToken());
}
}
现在我想开始在 .NetCore 2.0 和 SignalR 1.0.0 alpha 2 中进行开发
但我不知道如何在 Web API Controller 中实现管道、中间件或类似 costum ActionAttribute 的东西,我不在乎如何,基本上我需要 OnBeforeIncoming 功能。
我搜了一下,只找到了 this article但它很旧,不适用于新版本。
最佳答案
总结此处列出的内容以及此帖子链的指向。
Here is the proposal最终创建并用于网络核心信号器,以实现与 HubPipelineModule 类似的效果
and here is a link to documentation on it
如果你好奇... Here's documentation on filters in general
如果你和我一样,你会发现这个部分对编写你自己的过滤器特别有用
Exception catching filters
根据我自己的经验,我很害怕弄清楚如何使用它,因为我使用的是 net core 3.1 而不是 5.0。 5.0 有 AddFilter 调用可用。
关于asp.net-core - AspNetCore 2.0 + signalR 1.0.0 alpha2 添加管道或中间件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47703844/