0

I have a code which changes the UserId as it is written all over.

I've implemented the IUserIdProvider:

public class CustomUserIdProvider : IUserIdProvider
{
    public string GetUserId(IRequest request)
    {
        string userId = "userName";
        return userId;
    }
}

And added this provider to the startup class (Configuration function):

var idProvider = new CustomUserIdProvider();
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider);

I expect that all User Ids in all the hub will be "userName". I know (or maybe not?) that in order to obtain the UserId in one of the Hub functions, I need to get the value of:

Context.User.Identity.Name

But in fact, this value doesn't contain "userName", but different values:

  1. Empty when it's anonymous authentication
  2. The Windows user name in case of Windows Authentication.

In the Hub, when I look at Clients.User("userName"), I see that it's the real connection Id, so something happened (and the debugger stops at the implemented GetUserId function), but still, In the production code I won't know anything about the Custom User Id, and I want to fetch it somehow...

More Info: VS2012, IIS Express.

Programmer
  • 35
  • 10
  • Possible duplicate of [SignalR - Sending a message to a specific user using (IUserIdProvider) \*NEW 2.0.0\*](http://stackoverflow.com/questions/19522103/signalr-sending-a-message-to-a-specific-user-using-iuseridprovider-new-2-0) – Darren Wainwright Dec 05 '16 at 14:10
  • I don't think so. The question you linked presumes that Context.User.Identity.Name will contain the **new** user Id (as the same I did). – Programmer Dec 05 '16 at 14:19

0 Answers0