Membership get user Id
Posted on: Wed Feb 17 18:01:37 -0800 2010. Updated on: Wed Feb 17 18:03:32 -0800 2010.
Category: DotNet
Category: DotNet
This is useful to get the user ID object that a user is represented by in the database. It is the providerKey property of the Membership user object. Note that it comes back as an object and then you need to cast it usually to a Guid or sometimes an int, depending on your database schema and Membership provider.
// note you may want to check if the Membership.GetUser() is null before accessing properties. Guid userId = (Guid)Membership.GetUser().ProviderUserKey;