Search code examples
asp.net-coreasp.net-core-identity

.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!


Solution

  • 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);