Sharepoint - CurrentUser.IsSiteAdmin should be true but returns false
Probably it occurs since you are using App-only policy type
for authorization .
According to App authorization policy types in SharePoint 2013:
App-only policy—When the app-only policy is used, SharePoint checks only the permissions of the app principal. Authorization check succeeds only if the current app has sufficient permissions to perform the action in question, regardless of the permissions of the current user (if any).
In that case Web.CurrentUser
returns App principal and not real user:
using (var ctx = TokenHelper.GetClientContextWithAccessToken(
webUrl, sharePointAuthResult.AccessToken))
{
var currentUser = ctx.Web.CurrentUser; // app principal(!)
ctx.Load(currentUser);
ctx.ExecuteQuery();
}
To determine whether user is site collection administrator you could try to request the user first:
using (var ctx = TokenHelper.GetClientContextWithAccessToken(webUri.ToString(), accessToken))
{
var user = ctx.Web.EnsureUser(accountName);
ctx.Load(user);
ctx.ExecuteQuery();
var isAdmin = user.IsSiteAdmin;
}
Update
Another way to determine whether user is site collection administrator
Supported in SharePoint 2010/2013
public static bool IsUserSiteAdmin(ClientContext ctx,int userId)
{
var userInfoList = ctx.Site.RootWeb.SiteUserInfoList;
var item = userInfoList.GetItemById(userId);
ctx.Load(item);
ctx.ExecuteQuery();
return (bool)item["IsSiteAdmin"];
}
Usage
using (var ctx = new ClientContext(url))
{
var currentUser = ctx.Web.CurrentUser;
ctx.Load(currentUser);
ctx.ExecuteQuery();
var isCurrentUserSiteAdmin = IsUserSiteAdmin(ctx, currentUser.Id);
}