How Can I get UserId from ConnectionId in asp.net identity framework SignalR?
问题 I am using Asp.net Identity framework for authentication. Now I need the User id of connected client from connectionId or role of connected user. 回答1: public class WhateverHub : Hub { public override Task OnConnected() { //Get the username string name = Context.User.Identity.Name; //Get the UserId var claimsIdentity = Context.User.Identity as ClaimsIdentity; if (claimsIdentity != null) { // the principal identity is a claims identity. // now we need to find the NameIdentifier claim var