Hey, I have question, I configured default Identity in my web app in asp net.core 2.1, and I need details of current sign in user. How can do that???
In controller I can do :
private readonly UserManager _userManager;
private readonly UserManager
ApplicationUser x = await _userManager.GetUserAsync(User);
x.SomeFieldsOrMethods
but I need access to these fields in other .cs file where I have a SignalR Hub functions and there I haven't access to the 'User'.
In other way I tried :
After each sign in I add two new claims
await UserManager.AddClaimAsync(user, new Claim("UserLogin", user.Login));
await UserManager.AddClaimAsync(user, new Claim("UserId", user.Id.ToString()));
then in my Hub.cs file :
var httpcontext = Context.GetHttpContext();
string login = httpcontext.User.FindFirst("UserLogin").Value; <--this get a login well
string login = httpcontext.User.FindFirst("UserId").Value; <-- this get an UserId, but in string type, but iny my database I have integer Id. I tried parse to int in few ways but always failed.
var httpcontext = Context.GetHttpContext();
string login = httpcontext.User.FindFirst("UserLogin").Value; <--this get a login well
string login = httpcontext.User.FindFirst("UserId").Value; <-- this get an UserId, but in string type, but iny my database I have integer Id. I tried parse to int in few ways but always failed.
Please help me, how can I get user id (int) and other fields in other .cs files.
Thanks

Laxmidhar SahooRank #383 · 6.6K reputationPosted Nov 19, 2018, 3:18 AM EST
Dawid Ruchniewicz29 reputationPosted Nov 19, 2018, 3:24 AM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Nov 19, 2018, 3:32 AM EST
Dawid Ruchniewicz29 reputationPosted Nov 19, 2018, 3:40 AM EST
Laxmidhar Sahoo,
Dawid Ruchniewicz29 reputationPosted Nov 19, 2018, 7:22 AM EST
Laxmidhar SahooRank #383 · 6.6K reputationPosted Nov 19, 2018, 4:45 PM EST