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 SahooPosted Nov 19, 2018, 9:45 PM
Dawid RuchniewiczPosted Nov 19, 2018, 12:22 PM
Dawid RuchniewiczPosted Nov 19, 2018, 8:40 AM
Laxmidhar Sahoo,
Laxmidhar SahooPosted Nov 19, 2018, 8:32 AM
Dawid RuchniewiczPosted Nov 19, 2018, 8:24 AM
Laxmidhar SahooPosted Nov 19, 2018, 8:18 AM