我需要将User.Identity.Name
传递给Windows窗体客户端。为什么Context.User.Identity.Name在Windows Form Hub上下文中为null?
方法
public override Task OnConnected() {
string userName = Context.User.Identity.Name;
string connectionId = Context.ConnectionId;
var user = Users.GetOrAdd(userName, _ => new User {
Name = userName,
ConnectionIds = new HashSet<string>()
});
lock (user.ConnectionIds) {
user.ConnectionIds.Add(connectionId);
if (user.ConnectionIds.Count == 1) {
Clients.Others.userConnected(userName);
}
}
return base.OnConnected();
}
但Context.User.Identity.Name
为空?为什么?如何解决它?
也许你正在运行到这里所描述的同样的问题:http://stackoverflow.com/questions/22002092/context-user-identity-name-is-null-with-signalr-2-0-2-how-to-fix-it基本上,你必须在设置你的认证之后调用app.MapSignalR *。 – halter73
http://stackoverflow.com/questions/35794541/how-assign-a-connectionid-to-username-which-is-send-from-client-to-server-in-sig – Khalid