5

I do have a client context ClientContext context and current user:

var currentUser = context.Web.CurrentUser;

context.Load(currentUser);

context.ExecuteQuery();

I can also use rest API.

0

Solved this using Graph API rest request:

https://graph.windows.net/me/memberOf?api-version=1.6

Documentation: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations

0

I use this for SharePoint Online:

_clientContext.Load(_clientContext.Site, s => s.Url);
_clientContext.ExecuteQueryRetry();
var tenantUrl = $"https://{new Uri(_clientContext.Url).Host.Replace(".sharepoint.com", "-admin.sharepoint.com")}";
var tenantCtx = new ClientContext(tenantUrl);
tenantCtx.Credentials = _clientContext.Credentials;
var tenant = new Tenant(tenantCtx);
var props = tenant.GetSitePropertiesByUrl(_clientContext.Site.Url, false);
tenant.Context.Load(props);
tenant.Context.ExecuteQuery(); // will throw 401 exception here, if current user is not tenant admin
-1

Try this:

if (clientcontext.Web.CurrentUser.IsSiteAdmin) 
{
   Your Code
}
  • this returns if a user is a site admin. user can be or not be a site admin when he is a global admin. – Vitalik Zaidman Mar 15 '16 at 8:24
  • I am not sure about how to do it with CSOM but why not try with PowerShell? You will get the list of users who are Global Admins office365support.ca/… – Zakir HC Mar 15 '16 at 8:59
  • I'm developing an application where Global Admin has admin features so i need to check this in runtime. – Vitalik Zaidman Mar 15 '16 at 9:04
  • sometimes this code Web.CurrentUser.IsSiteAdmin fails in onpremises.i have tested multiple times within a visual web part, event receivers for checking a user is belonging to siteadmin or not. but it returns incorrect data. – userAZLogicApps Mar 15 '16 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.