Solved

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

Posted on 2011-03-22
4
593 Views
Last Modified: 2012-05-11
What is the Unique ID for Users in the ASPNETDB.MDF and how can it be accessed through VB or C#?  Thanks.
0
Comment
Question by:jigdog
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
_kiwi_ earned 500 total points
ID: 35197085
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
 

Author Comment

by:jigdog
ID: 35198790
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
 
LVL 3

Expert Comment

by:_kiwi_
ID: 35199032
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
 

Author Comment

by:jigdog
ID: 35199066
Wonderful, thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now