2

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.'
drma usama
  • 105
  • 1
  • 2
  • 10

1 Answers1

1

Found issue, I had to initialize at end of startup.cs

app.MapSignalR();
drma usama
  • 105
  • 1
  • 2
  • 10