sharepoint 判断当前用户在当前页面是否有某项权限

下面的代码用于判断当前用户是否对当前页面有编辑权限,原理是对页面权限进行&操作,再判断是否为空:
&表示与操作
|表示或操作

bool haveEditPermission = true;
if (SPContext.Current.Web.CurrentUser != null && SPContext.Current.ContextPageInfo.BasePermissions.HasValue)
{
//判断当前用户有编辑当前页面的权限
if((SPContext.Current.ContextPageInfo.BasePermissions.Value&SPBasePermissions.EditListItems)!=SPBasePermissions.EmptyMask)
{
haveEditPermission = true;
}


备注:调用base.SetPersonalizationDirty()设置webpart属性时无需判断用户权限,没有权限的用户是不会设置成功的

原文地址:https://www.cnblogs.com/ruijian/p/2748816.html