SignalR Client How to Set user when start connection?

前端 未结 4 1417
走了就别回头了
走了就别回头了 2021-02-04 09:46

Server side:

public override Task OnConnected()
{
    var connectionId = Context.ConnectionId;
    var user = Context.User.Identity.Name; // Context.User is NULL         


        
4条回答
  •  野性不改
    2021-02-04 09:56

    Client

    var connection = new HubConnection();
    connection.Headers.Add("username", "maria");
    var myHub = connection.CreateHubProxy("MyHub");
    

    Server

    string username = Context.Headers.Get("username");
    Console.WriteLine("New client connection - " + username);
    

提交回复
热议问题