Get logged in user's id

Try this:

using Microsoft.AspNet.Identity;
User.Identity.GetUserId();

That's how its done in the partial views for current MVC (MVC5/EF6/VS2013) templates.

Correct me if I'm wrong, because I've seen Aviatrix's answers a lot, but what happens if more than one user has the same name in the database?


I think you're looking for ProviderUserKey - Gets the user identifier from the membership data source for the user.

object id = Membership.GetUser().ProviderUserKey

Membership.GetUser() - Gets the information from the data source and updates the last-activity date/time stamp for the current logged-on membership user.


The best way to do so is to use the WebSecurty class

var memberId = WebSecurity.GetUserId(User.Identity.Name);

and don't forget to add [InitializeSimpleMembership] on top of your controller :)