User service

The UserService class is one of the Service classes available. The UserService provides functionality for handling users, roles and authentication. The UserService is often used on intranet and extranet to handle logins and permissions.

Examples

Here are some examples on how and when to use the UserService class

Example 1. Authenticate a user

var user = UserService.Authenticate(username.Text, password.Text);

if (user != null) {
    // do something
} else{
    // not authenticated
}

 

Example 2. Login a user to a intranet/extranet

var user = UserService.Authenticate(username.Text, password.Text);
                    
if (user != null){
    message.InnerHtml = String.Format("Welcome {0}", user.Name);
    FormsAuthentication.SetAuthCookie(user.Username, false);
    Response.Redirect(ContentHelper.ResolveUrl(Content, false), false);
} else {
    message.InnerHtml = "Incorrect username and password";
}

 

Example 3. Search for all users named "peter"

var query = new UserQuery();
query.Text = "peter";
var users = UserService.Search(query);