Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to determine if a user is a site collection admin in SharePoint 2013 Preview but am encountering some weirdness. I add myself as a site collection admin in the settings panel then use the following code to test my credentials. Please note that I am also testing to see if the user is in the owners group.

protected void Page_Load(object sender, EventArgs e)
{
    ...           
    clientContext.Load(clientContext.Web);
    clientContext.Load(clientContext.Web.CurrentUser);
    clientContext.Load(clientContext.Web.CurrentUser.Groups);
    clientContext.Load(clientContext.Web.AssociatedOwnerGroup);

    clientContext.ExecuteQuery();
    _isOwner = isUserOwnerOrAdmin(clientContext);
    ...
}


private bool isUserOwnerOrAdmin(ClientContext clientContext, bool checkForSiteAdmin = true)
{
    bool flag = false;
    if (clientContext.Web.CurrentUser.IsSiteAdmin && checkForSiteAdmin)
    {
        flag = true;
    }
    else
    {
        foreach (Group group in clientContext.Web.CurrentUser.Groups)
        {
            if (group.Id == clientContext.Web.AssociatedOwnerGroup.Id)
            {
                flag = true;
                break;
            }
        }
    }

    return flag;
}

When I inspect the following line in isUserOwnerOrAdmin(), it is false. Obviously I am expecting IsSiteAdmin to be true...

if (clientContext.Web.CurrentUser.IsSiteAdmin && checkForSiteAdmin)

The CurrentUser object is populating as I would expect and shows the email address of my account, so it is getting something back from the server and it is looking at the right user but doesn't seem to be able to identify that I'm an admin.

I've googled around the problem and found lots of suggestions that would work for SharePoint 2010 or SharePoint on-prem but nothing for SharePoint Online 2013.

Help!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.