向SignalR客户端添加角色

问题描述:

我学习了SignalR,并且我想为信号客户端添加一个角色。向SignalR客户端添加角色

在官方文件中,他们表示可以为每个客户添加一个特定的角色,并且我想知道这是可能的。

[Authorize(Roles = "Admin,Manager")] – only authenticated users in the specified roles 

所以,我可以这样做: (服务器部分)

public class MyHub : Hub 
{ 
    public void addToGroupe() 
    { 
     //add a role to the caller client to authorize him calling function 
     //Context.Caller ... ? 
    } 
} 

非常感谢!

您用该属性修饰方法,并在Web服务器上使用Form或Windows身份验证。

+0

haa,据我所知,这是Windows Server的角色?当你创建Windows客户端。好的,谢谢! – NoteStylet 2014-09-01 07:42:53

+0

如果您使用.NET客户端,则需要在连接上设置凭据。 Javascript客户端开箱即用 – Anders 2014-09-01 07:49:31