ste_irl ste_irl - 10 months ago 61
ASP.NET (C#) Question

Getting the GUID of the current user?

I want to add a user's GUID in with the information I retrieve from a user when they submit a post. How can I get the GUID?

I am using the default authentication system that comes along with an ASP.NET MVC application.

Answer Source

If you are using the ASP.NET Membership provider:

MembershipUser user = Membership.GetUser(User.Identity.Name);
Guid guid = (Guid)user.ProviderUserKey;

or simply:

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