答えて

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 userIdClaim = claimsIdentity.Claims 
       .FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier); 

      if (userIdClaim != null) 
      { 
       var userIdValue = userIdClaim.Value; 
      } 
     } 
     return base.OnConnected(); 
    } 
} 

は私がconnectionIDからユーザIDを必要とするあなたのHubクラス

+0

[Authorize]属性を使用することを忘れないでください?あなたはsignalIでconnectionIdを知っていますか?接続されたクライアントに固有の接続IDがあり、それらのcoectiondId userIdが必要ですか?私が何を意味するのか理解していますか? –

+0

'SignalR ConnectiondId'と' Identity UserId'( 'Users'テーブルの主キー)は同じではありません。あなたは何が必要ですか? –

+0

ありがとうございました:)その作品は今:)別の質問のために私を助けることができますか? –

関連する問題