我從JavaScript的發送的用戶ID,而我想提出請求signalr如下:SignalR IUserIdProvider不被調用用於用戶標識和的ConnectionId映射
var userId = "1";
var connection = $.hubConnection("/signalr", { useDefaultPath: false });
var notificationsHubProxy = connection.createHubProxy('NotificationsHub');
connection.qs = "userId=" + userId;
notificationsHubProxy.on('notify', function (notifications) {
notifyAll(notifications);
});
connection.start()
.done(function() {
notificationsHubProxy.invoke('getNotifications', "1,2,3");
})
.fail(function(reason) {
alert('signalr error');
});
下面是用於實施IUserIdProvider檢索查詢字符串並返回作爲用戶id類,我調試了,這個類和GetUserId方法沒有被框架調用。
public class RealTimeNotificationsUserIdProvider : IUserIdProvider
{
public string GetUserId(IRequest request)
{
return request.QueryString["userId"];
}
}
這是我與signalR配置掛鉤IUserId提供商啓動類:
var userIdProvider = new RealTimeNotificationsUserIdProvider();
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider),() => userIdProvider);
app.Map("/signalr", map =>
{
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true,
Resolver = dependencyResolver,
EnableJavaScriptProxies = false
};
map.RunSignalR(hubConfiguration);
});
現在,當我嘗試通過訪問Clients.User(用戶ID)發送通知給特定用戶的不工作:
var userId = "1";
Clients.User(userId).notify("test");
我在想什麼?請幫忙。