privatevoid CreateUser() { // Create new user object UserInfo newUser = newUserInfo(); // Set the properties newUser.FullName = "My new user"; newUser.UserName = "MyNewUser"; // Save the user UserInfoProvider.SetUserInfo(newUser); }
The following example gets and updates a user.
privatebool GetAndUpdateUser() { // Get the user UserInfo updateUser = UserInfoProvider.GetUserInfo("MyNewUser"); if (updateUser != null) { // Update the properties updateUser.FullName = updateUser.FullName.ToLower(); // Save the changes UserInfoProvider.SetUserInfo(updateUser); returntrue; } returnfalse; }
The following example gets and bulk updates users.
privatebool GetAndBulkUpdateUsers() { // Prepare the parameters string where = "UserName LIKE N'MyNewUser%'"; // Get the data DataSet users = UserInfoProvider.GetUsers(where, null); if (!DataHelper.DataSourceIsEmpty(users)) { // Loop through the individual items foreach (DataRow userDr in users.Tables[0].Rows) { // Create object from DataRow UserInfo modifyUser = newUserInfo(userDr); // Update the properties modifyUser.FullName = modifyUser.FullName.ToUpper(); // Save the changes UserInfoProvider.SetUserInfo(modifyUser); } returntrue; } returnfalse; }
The following example deletes a user.
privatebool DeleteUser() { // Get the user UserInfo deleteUser = UserInfoProvider.GetUserInfo("MyNewUser"); // Delete the user UserInfoProvider.DeleteUser(deleteUser); return (deleteUser != null); }
The following example checks if the credentials of a user are valid for a specified site using forms authentication.
privatebool AuthenticateUser() { // Get the user UserInfo user = UserInfoProvider.GetUserInfo("MyNewUser"); if (user != null) {
if (UserInfoProvider.AuthenticateUser("MyNewUser", "", CMSContext.CurrentSiteName) != null)