How do I verify user rights on SharePoint 2010 using the client object model?

The following code always returns false (which is incorrect since the user has full permission at the site level):

Site site;
BasePermissions permissionMask;
ClientResult<bool> result;

permissionMask = new BasePermissions();
permissionMask.Set(PermissionKind.ManageWeb);
result = site.DoesUserHavePermissions(permissionMask);

return result.Value;

I'm trying to use the new SharePoint 2010 client object model. I was delighted to find the DoUserHavePermissions method, but it seems I'm not sure if I know to use it. I have no idea if I am using the correct mask or should I specify the user account for which I want to check the permission level? Any help would be greatly appreciated. Thank you

+3
source share
2 answers

- . SharePoint Client.

:

ClientContext clientContext;
Site site;
BasePermissions permissionMask;
ClientResult<bool> result;

permissionMask = new BasePermissions();
permissionMask.Set(PermissionKind.ManageWeb);
//if we want to check ManageWeb permission
clientContext = new ClientContext(siteUri);
//siteUri is a method parameter passed as a string
clientContext.Credentials = credential;
//credential is a method parameter passed as a NetworkCredential object
//that is the user for which we are checking the ManageWeb permission
site = clientContext.Web;
result = site.DoesUserHavePermissions(permissionMask);

return result.Value;

true, ManageWeb, false, . .

+4

, , . , .

using (var context = new ClientContext(siteUrl))
{
   context.Load(context.Web);
   context.ExecuteQuery();
   BasePermissions permissionMask;
   ClientResult<bool> hasPermissions;
   permissionMask = new BasePermissions();
   permissionMask.Set(PermissionKind.ManageWeb);
   hasPermissions = context.Web.DoesUserHavePermissions(permissionMask);

}
+1

Source: https://habr.com/ru/post/1741945/


All Articles