Kentico CMS 7.0 Developer's Guide

Users and sites

Users and sites

Previous topic Next topic Mail us feedback on this topic!  

Users and sites

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example assigns a user to a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}

 

The following example removes a user from a site.

 

private bool 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);
 
        return true;
    }
 
    return false;
}