Solution For The Issue While Checking Permissions Of Ad - SharePoint Users In The SharePoint Site

Issue - You have a SharePoint site and you want to check the roles of the user.

Solution - You can do that easily by checking what kind of permission the users have.

For Ex - You might know that the owner will have full control & some other user may be contributing. In this case, you can check the specific permissions of the user like the owner can manage list items, add, delete, edit the Items but the other user can only add/delete/edit but cannot manage lists.

You can just perform the operation, stated above, using the code, given below-.

CSOM

  1. var _context = null;  
  2. if (_context == null)   
  3. {  
  4.     var Request = HttpContext.Current.Request;  
  5.     Uri _hostWeb = new Uri(Request.QueryString["SPHostUrl"]);  
  6.     _context = TokenHelper.GetS2SClientContextWithWindowsIdentity(_hostWeb, HttpContext.Current.User.Identity as System.Security.Principal.WindowsIdentity);  
  7.     _context.Load(_context.Web, w => w.EffectiveBasePermissions);  
  8.     _context.ExecuteQuery();  
  9. }  
  10. var IsOwner = _context.Web.EffectiveBasePermissions.Has(PermissionKind.ManageLists);  
Now, you can see, I have checked if the user with whom’s identity the context has been made has Manage lists Permission or not, which in turn states whether he is the owner or not.

You can also club the permissions and check if you have custom permission levels.

 

Ebook Download
View all
Learn
View all