C# 向用户订阅ServiceStack中的SSE通道
我正试图弄清楚如何使用ServiceStack的C# 向用户订阅ServiceStack中的SSE通道,c#,
servicestack,server-sent-events,C#,
servicestack,Server Sent Events,我正试图弄清楚如何使用ServiceStack的OnAuthenticated功能向刚通过身份验证的用户订阅SSE频道。 这是我的实际代码: public override void OnAuthenticated(IRequest httpReq, IAuthSession session, IServiceBase authService, IAuthTokens tokens, Dictionary<string, string> authInfo) { string
OnAuthenticated
功能向刚通过身份验证的用户订阅SSE频道。
这是我的实际代码:
public override void OnAuthenticated(IRequest httpReq, IAuthSession session, IServiceBase authService, IAuthTokens tokens, Dictionary<string, string> authInfo) {
string subscriptionId = // ???;
string[] channels = { "mychan1", "mychan2" };
ServerEvents.SubscribeToChannels(subscriptionId, channels);
}
public override void OnAuthenticated(IRequest httpReq、IAuthSession会话、IServiceBase authService、IAuthTokens令牌、字典authInfo){
字符串下标ID=/???;
字符串[]通道={“mychan1”、“mychan2”};
订阅通道(订阅ID,通道);
}
我的问题是:我如何将subscriptionId
绑定到刚刚通过身份验证的用户,以便向他/她订阅频道
多谢各位 您不能在会话中代表用户订阅,客户端需要使用建立自己的已验证服务器事件连接,例如: 初始化服务器事件客户端:
var client = new ServerEventsClient(baseUri, channel=channelName) {
// Register any handlers...
};
使用内置服务客户端进行身份验证:
client.ServiceClient.Post(new Authenticate {
provider = "credentials",
UserName = "user",
Password = "pass",
RememberMe = true,
});
启动ServerEventsClient
以建立经过身份验证的服务器事件连接:
client.Start();
或者,例如与不同的身份验证提供程序(如JWT)建立经过身份验证的服务器事件连接。谢谢你,mythz,据我所知,无法向用户订阅服务器端的通道?@wizzy需要建立从客户端直接到SSE/事件流的持久连接,因此没有。