Solved

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

Posted on 2011-03-22
4
592 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
Comment Utility
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
Comment Utility
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_
Comment Utility
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
Comment Utility
Wonderful, thanks for your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

12 Experts available now in Live!

Get 1:1 Help Now