Reputation: 105
I followed this answer but Im getting Null in Irequest request.User
SignalR - Sending a message to a specific user using (IUserIdProvider) *NEW 2.0.0*
I created a class in app_start folder like this
public class CustomUserIdProvider : IUserIdProvider
{
public string GetUserId(IRequest request)
{
// your logic to fetch a user identifier goes here.
// for example:
var userId = request.User.Identity.Name;
return userId.ToString();
}
}
After this I initialize new costom provider in Startup.cs like this :
public void Configuration(IAppBuilder app)
{
var idProvider = new CustomUserIdProvider();
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider);
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
But Im getting exception on line
var userId = request.User.Identity.Name;
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Upvotes: 2
Views: 284
Reputation: 105
Found issue, I had to initialize at end of startup.cs
app.MapSignalR();
Upvotes: 1