2014-08-31 214 views
0

我學習了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 ... ? 
    } 
} 

非常感謝!

回答

2

您用該屬性修飾方法,並在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