Verify current user access on current site

Updated: Sep 15, 2020

In this blog we will see how if current user having permissions a site

string webUri = //your site url;
using (ClientContext context = new ClientContext(webUri)) {  
    Web rootWeb = context.Site.RootWeb;
    context.Load(rootWeb);
    BasePermissions permission = new BasePermissions();
    permission.Set(PermissionKind.ManageWeb);
    ClientResult result= rootWeb.DoesUserHavePermissions(permission);
    try
    {                
        context.ExecuteQuery();
        if(result.Value){
            Console.WriteLine("You have access");
        }
        else{
     Console.WriteLine("You don't have access"); 
        }
    }
    catch(Exception ex)
    {
        Console.WriteLine("You don't have access");
    }
} 
 

Refer MSDN


2 views0 comments

Recent Posts

See All

In this blog we will see how to export a list in excel using server side object model. First block we will retrieve all items from the list. This can be done in several ways. You can get all items wit