Mronzer
Mronzer

Reputation: 449

Get current logged in user's email address is timming out

I am using the Membership.GetUser(User.Identity.Name).Email method to try and get the current user email address but its timing out, I just have one line, on which I declare and assign the returned value of the method to a variable Here is my one line of code string userEmail = Membership.GetUser(User.Identity.Name).Email;,

I have tried this code both with or without the username parameter. I also tried checking first if user is authenticated but once it gets to this line it times out, I have also tried doing it totally from a different method.

Note: Windows auth is used on the web app

Upvotes: 0

Views: 974

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239380

Membership is from ASP.NET Membership, not Identity. You need to use:

var user = UserManager.FindById(User.Identity.GetUserId());

Then, you access the Email property off that user object.

UPDATE

I got thrown by your use of the [asp.net-identity] tag. However, the same over all point applies. Membership is from a completely different authentication system than Windows Auth. When using Windows Auth, your user information comes from AD, so you simply need to add a UserPrincipal extension if you need additional information. See my answer in this related question.

Upvotes: 1

Related Questions