Query user profiles

The most common ways to query a user profiles are:

  • by user’s ID
  • by username

In this examples, you make a query for the specified user and pass it to the GetUserPofile<T> method of the manager.

Querying a profile by user’s ID

Querying a profile by username

The code for querying a user profile by username is similar to the one for querying user profiles by user’s ID. The only difference is that you query the user by calling the GetUser(string username) overload.

Alternatively, you can make a query for all the profiles and filter them by a desired criteria. You must call the desired overload of the GetUserProfiles method. Note that it returns all available profiles no matter their type. If you have other profile implementations, you must filter the collection by the type of the profile.

Querying a profile by user’s ID
Querying all profiles

Querying all profiles by role

In the code above, you get an instance of the role manager class by passing the provider name for the predefined roles that are built in Sitefinity CMS. Using the role manager you get all the users in a specific role. Next, you get an instance of the user profile manager class and get all the user profiles. Finally, you match the user ID's of the user profiles with the user ID's of the users in the specified role and return the result.

Was this article helpful?

Next article

Modify user profiles