Tim
Tim

Reputation: 583

.net core get data for a user not the current user -- Identity

I have the following which gets me my info:

        public async Task<IActionResult> OnGetAsync()
    {
        var user = await _userManager.GetUserAsync(User);
        if (user == null)
        {
            return NotFound($"Unable to load user with ID 
            '{_userManager.GetUserId(User)}'.");
        }

        var userName = await _userManager.GetUserNameAsync(user);
        var email = await _userManager.GetEmailAsync(user);
        var phoneNumber = await _userManager.GetPhoneNumberAsync(user);

        Username = userName;

        Input = new InputModel
        {
            Email = email,
            PhoneNumber = phoneNumber,
            FriendlyName = user.FriendlyName
        };

        IsEmailConfirmed = await _userManager.IsEmailConfirmedAsync(user);

        return Page();
    }

How would I get another users info... how to pass user that is not the current user I guess. I have tried several things and I think i'm missing something obvious here.

Thanks!

Upvotes: 0

Views: 802

Answers (2)

Set
Set

Reputation: 49779

There are UserManager<TUser>.FindByXXX() methods that return user object:

Task<TUser> FindByEmailAsync(string email);
Task<TUser> FindByIdAsync(string userId);
Task<TUser> FindByLoginAsync(string loginProvider, string providerKey);
Task<TUser> FindByNameAsync(string userName);

Upvotes: 2

Tim
Tim

Reputation: 583

Ended up using this:

var user = await _userManager.FindByIdAsync(Userid);

Getting Userid from the route.

Upvotes: 0

Related Questions