简体   繁体   中英

How can I send signalr message to just unauthenticated/public users?

I want to send signalr message to clients except authenticated ones. Can I do this ?

Or, If there is a way to understand user is authenticated or not on client side when signalr message comes, it also solves my problem. But I can't use ajax calls.

You will have to solve it yourself, iterate over all users, check which ones are authenticated and send message specific to that client id(Ids since one user can have several windows open).

This could be pretty elegantly solved with my SignalR.EventAggregator library, here is a relevant blog post for how you could solve it.

http://andersmalmgren.com/2014/06/12/client-server-event-aggregation-with-role-authorization/

You can use SignalR groups . When an unauthenticated user connects, add them to an Unauthenticated group. When they authenticate, remove them from Unauthenticated and add them to Authenticated. When you want to send a message to one of the groups, all you need is a simple:

Clients.Group("authenticated").MyCoolMessage(message);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM