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.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Modify user profiles