How to get the UserID of a User object in ASP.Net MVC


I have some tables that have a uniqueidentifier UserID that relates to aspnet_Users.UserID. When the user submits some data for those tables, since the controller method has an [Authorize] I get a User object. I can get the username with User.Identity.Name, but how do I get the UserID to be able to establish (the ownership) relationship?

Best Solution

It seems you cannot get it from the User object but you can get it this way:

Guid userGuid = (Guid)Membership.GetUser().ProviderUserKey;