Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to send a message to a role #3418

Closed
SirwanAfifi opened this issue Mar 1, 2015 · 3 comments
Closed

Add ability to send a message to a role #3418

SirwanAfifi opened this issue Mar 1, 2015 · 3 comments

Comments

@SirwanAfifi
Copy link

In SignalR we have this ability (sending message for a user)
What if we want to send a message to a role or roles? for example something like this:

Clients.Role("Administrator").send(message);

It would be better to have this ability.
In my case I send message for Administrator users this way:

public override Task OnConnected()
        {
            var userRole = "";
            userRole = Context.User.Identity.IsAuthenticated ? _userManager.GetRolesAsync(int.Parse(Context.User.Identity.GetUserId())).Result.FirstOrDefault() : "Users";
            Groups.Add(Context.ConnectionId, userRole);
            return base.OnConnected();
        }

Then I'll send message to specific role this way:

Clients.OthersInGroup("Administrator").send(message); 
@DamianEdwards
Copy link
Member

Thanks for the suggestion. You could certainly do this today yourself my adding connections to groups named after the roles the user is in and then sending to those groups. You have to be careful how you expose groups however, such that you don't inadvertently let users construct group names themselves that might allow them to have messages sent to groups that represent roles (if you don't want to allow that). If we supported this as a first class feature we can prevent by way of our signal prefixes (essentially namespaces for known signal types to avoid clashes).

I've tagged this as a v3 candidate and as such it'll get moved to the new repo when we start looking at v3 features.

@sharathdevadiga
Copy link

SirwanAfifi - I am searching for the sample on how to "send a message to a role" and i am not able to find a solution to this. Did you get the answer to the above solution? Can you please share the sample code.

Thanks

@aspnet-hello
Copy link

This issue has been closed as part of issue clean-up as described in https://blogs.msdn.microsoft.com/webdev/2018/09/17/the-future-of-asp-net-signalr/. If you're still encountering this problem, please feel free to re-open and comment to let us know! We're still interested in hearing from you, the backlog just got a little big and we had to do a bulk clean up to get back on top of things. Thanks for your continued feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants