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

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;

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.