There is no way to retrieve the new generated id. Since you have an IRequest object available to you inside of Hub methods and inside of PersistentConnection.OnReceived, the idea is you should be able to derive the caller's UserId from the IRequest in your Hub methods the same way you did in your custom GetUserId method.
Your example implementation would not be useful because you do not return the same id for every request made by the same caller. One option you might have is to identify your user is by extracting their user id from the query string which you can customize. However, you will have to be careful about how you do this if you don't want it to be possible to spoof UserIds.
Once you have a way to extract the same UserId from all IRequests coming from he same caller, you should be able to do something like the following:
public class CustomUserIdProvider : IUserIdProvider
{
public string GetUserId(IRequest request)
{
//for example
return MyStatic.ExtractUserId(request);
}
}
public class MyHub : Hub
{
public string GetMyUserId()
{
return MyStatic.ExtractUserId(Context.Request);
}
public void SendToUser(string userId, string message)
{
Clients.User(userId).send(message);
}
}