How to get user email address from ASP.NET MVC Default Mempership Model?

后端 未结 4 1605
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 18:45

i can get the user name as : User.Identity.Name. How can I user\'s email address because it must be stored (there is a textbox for it in the registration form)?

相关标签:
4条回答
  • 2021-02-13 19:01

    On MVC5, you can use the UserManager for that, like this:

    string UserEmail = await UserManager.GetEmailAsync(User.Identity.GetUserId());
    
    0 讨论(0)
  • 2021-02-13 19:17
    if(User.Identity.IsAuthenticated)
    {
        someLabel.Text = Membership.GetUser().Email;
    }
    

    There are a lot of useful user properties resulting from the Membership.GetUser() function. It returns an object of type MembershipUser.

    0 讨论(0)
  • 2021-02-13 19:19

    or if the information is coming from outside the page you can do like this.

     string userName = Request.QueryString["username"];
    
         TextBoxUserID.Text = Membership.GetUser(userName).Email;
    
    0 讨论(0)
  • 2021-02-13 19:21
    protected string GetEmailAddress()
    {
        MembershipUser currUser = null;
        if (HttpContext.Current.User != null)
        {   
            currUser = Membership.GetUser(true);
            return currUser.Email; 
        }   
        return currUser.Email;
    }
    
    0 讨论(0)
提交回复
热议问题