Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net-mvc

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)?

like image 886
Radi Avatar asked Sep 21 '10 15:09

Radi


2 Answers

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.

like image 93
Jsinh Avatar answered Oct 26 '22 21:10

Jsinh


protected string GetEmailAddress()
{
    MembershipUser currUser = null;
    if (HttpContext.Current.User != null)
    {   
        currUser = Membership.GetUser(true);
        return currUser.Email; 
    }   
    return currUser.Email;
}
like image 31
A_Var Avatar answered Oct 26 '22 21:10

A_Var