privatebool AddUserToSite() { // Get the user UserInfo user = UserInfoProvider.GetUserInfo("MyNewUser"); if (user != null) { int userId = user.UserID; int siteId = CMSContext.CurrentSiteID; // Save the binding UserSiteInfoProvider.AddUserToSite(userId, siteId); returntrue; } returnfalse; }
The following example removes a user from a site.
privatebool RemoveUserFromSite() { // Get the user UserInfo removeUser = UserInfoProvider.GetUserInfo("MyNewUser"); if (removeUser != null) { int siteId = CMSContext.CurrentSiteID;
// Get the binding UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(removeUser.UserID, siteId);
// Delete the binding UserSiteInfoProvider.DeleteUserSiteInfo(userSite); returntrue; } returnfalse; }