/// <summary> /// Sets the site collection administrator for the activity /// </summary> /// <param name="_siteUrl">The relative url to the site collection</param> /// <param name="userNameWithoutClaims">Provide the username without the claim prefix</param> /// <param name="isSiteAdmin">(OPTIONAL) true to set the user as a site collection administrator</param> protected virtual void SetSiteAdmin(string _siteUrl, string userNameWithoutClaims, bool isSiteAdmin = false) { var claimProviderUserName = string.Format("{0}|{1}", ClaimIdentifier, userNameWithoutClaims); if (isSiteAdmin) { LogVerbose("Granting access to {0} for {1}", _siteUrl, claimProviderUserName); } else { LogVerbose("Removing access to {0} for {1}", _siteUrl, claimProviderUserName); } try { if (TenantContext.Context == null) { this.ClientContext.Load(TenantContext); this.ClientContext.ExecuteQueryRetry(); } TenantContext.SetSiteAdmin(_siteUrl, claimProviderUserName, isSiteAdmin); TenantContext.Context.ExecuteQueryRetry(); } catch (Exception e) { LogError(e, "Failed to set {0} site collection administrator permissions for site:{1}", userNameWithoutClaims, _siteUrl); } }