We all started to use the new asp.net identity for our user management in asp.net applications. In your asp.net identity system if you are using plain user name as login username then in situations you may need to get the registered user’s email if you want to send a mail or to show a list of users along with their email in the back end of your application. The asp.net identity usermanager offers 3 ways to get the user information by using

  1. Email
  2. username
  3. userid

since we want to find the email, we should have either the username or userid to get the email. Let us see both options

Using UserName


string useremail;

string username="jondoe";

var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

ApplicationUser user =  manager.FindByName(username);

useremail= user.Email;

 

Using UserID


 

string useremail;

string userid="45B9C6B3-34D6-43D0-8891-B91F8B00B77E"; //sample registered user id,

var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

ApplicationUser user =  manager.FindById(userid);

useremail= user.Email;

From the snippet just use the string useremail to your output.

To use the Application User Manager you need the following namespaces


using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;

You should have the ASP.NET IDENTITY installed your application as well