Pergunta

I wonder if there is any way to map a ConnectionId to the user without using IPrincipal.Identity.Name. I am already using a custom class "IUserIdProvider" to generate a userId

public class CustomUserIdProvider : IUserIdProvider
{
     public string GetUserId(IRequest request)
    {
        // your logic to fetch a user identifier goes here.
        // for example:

        ////////////////////////////////////////////////////////////////////////
        //**I do not want to use the code below to find the User in my database**
        var userId = MyCustomUserClass.FindUserId(request.User.Identity.Name);
        /////////////////////////////////////////////////////////////////////////

        return userId.ToString();
    }
}

This is all because I'm not using ASP.NET authentication method. The real need is to find a way to pass the user ID to make the association with ConnectionId of time.

I need a way to give (or receive) the identifier of the data from my database User (user_id) in this method. Or some other way (logic) to associate the user with ConnectionId.

Thanks in advanced!

Foi útil?

Solução

You can pass parameters about the connected user in the query string from the client to the server like this :

On the client side :

$.connection.hub.qs = "myUser=user";

On the server side :

var myUser= Context.QueryString["myUser"];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top