• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

What is the Unique ID for Users in the ASPNETDB.MDF

What is the Unique ID for Users in the ASPNETDB.MDF and how can it be accessed through VB or C#?  Thanks.
0
jigdog
Asked:
jigdog
  • 2
  • 2
1 Solution
 
_kiwi_Commented:
Hello,

In this database, the unique ID for Users is an automatically generated GUID (Globally Unique IDentifier) stored in the UserId column of the aspnet_Users in the ASPNETDB.MDF (or any other source: SQL Express, ...) database.

You should never rely on this data directly but always use:
- User related functions: System.Web.Security.Membership class (e.g. Membership.GetUser() Gives you the logged-in user, with a ProviderUserKey property that is the GUID of this user)
- Role related functions: System.Web.Security.Roles class (e.g. Roles.IsUserInRole() tells you if the current user is in a particular role)
- Profile related functions: System.Web.Profile.ProfileManager class

--> Answer to the first question: to get the user ID: (Guid) System.Web.Security.Membership.GetUser().ProviderUserKey
This only works this way because it is ASPNetDB in the backend, it can be different with other Membership Providers.

Otherwise (**Highly not recommended**) you have a connectionString called "ApplicationServices" in your Web.Config that points to the database, and starting from the current user's guid you can query through SQL Queries the database, it is either an access or a plain SQL Database, you can mount it in Visual Studio and look through the data.

Hope this helps,
Julien
0
 
jigdogAuthor Commented:
Thank you for your answer.  Before I award points, could i ask:  is there a way to list all current users in the ASPNETDB?  
0
 
_kiwi_Commented:
System.Web.Security.Membership.GetAllUsers() will get that for you.

An alternative exists that supports paging:
System.Web.Security.Membership.GetAllUsers(pageIndex, pageSize, out totalRecords)

Have a nice day,
Julien
0
 
jigdogAuthor Commented:
Wonderful, thanks for your help.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now