Query users

This topic contains examples of how to:

  • Query a single user
  • Query all users
  • Query user by first name

Querying a single user

To query a specific user, you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get the user.
    To get the specified user, call the GetUser method of the UserManager class. It has two overloads:
    • GetUser(string username) – returns the user with the specified username.
    • GetUser(Guid id) – returns the user with the specified ID.

NOTE: To learn how to query the profile of the user, read For developers: Query user profiles.

Here is a code example:

Querying all users

To query all users, you must perform the following:

  1. Get instance of the user manager.
    The manager is represented by the UserManager class. For more information about getting the instance, see For developers: Users.
  2. Get all users.
    To get all users, call the GetUsers method of the UserManager class.

Here is a code example:

Querying a user by first name

Normally you can get the user object by any of the User class properties. For example in order to get a user by username, you can use the following code:

However some of the fields of the user are no longer properties of the User class like first name and last name. Instead you should use the SitefinityProfile. Here is a sample code that demonstrates how to query all users by first name:




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 users