In this blog we will see how if current user having permissions a site
Refer MSDN
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");
}
}
Here basePermissions.Set(PermissionKind.ManageWeb); refers to access on web. Microsoft has provided more permissions levels we can verify.Refer MSDN
No comments :
Post a Comment