SharePoint 2010 获取当前用户的权限

本文介绍如果获取当前登录用户权限(所有操作都是在可视Web部件中进行的):

1.判断当前用户是否具有完全控制权限

SPWeb web=SPContext.Current.Web; 

SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser; 

SPRoleDefinitionCollection siteRoleCollection = web.RoleDefinitions; 

SPRoleDefinition roleDefinition = siteRoleCollection["完全控制"];   

if (usersRoles.Contains(roleDefinition)) 

  {                

     //具有完全控制权限 

  } 

SPWeb web=SPContext.Current.Web;

SPRoleDefinitionBindingCollection usersRoles = web.AllRolesForCurrentUser;

SPRoleDefinitionCollection siteRoleCollection = web.RoleDefinitions;

SPRoleDefinition roleDefinition = siteRoleCollection["完全控制"];

if (usersRoles.Contains(roleDefinition))

{

//具有完全控制权限

}

注意,如果你的sharepoint 版本是英语版本,请将完全控制四个字换成:Full Control

2.判断当前用户所在的组

SPWeb web=SPContext.Current.Web;   

SPGroup group = web.Groups["Team Site所有者"]; 

if (group.ContainsCurrentUser) 

   //当前用户在"Team Site所有者"组内 

SPWeb web=SPContext.Current.Web;

SPGroup group = web.Groups["Team Site所有者"];

if (group.ContainsCurrentUser)

{

//当前用户在"Team Site所有者"组内

}

注意:如果你的是英文版本,请将Team Site所有者 换成:Team Site Owners

总结:能获取当前用户所在的权限组及用户组,也就知道当前登录用户的权限了。

转自:http://blog.csdn.net/sygwin_net/article/details/6790500

原文地址:https://www.cnblogs.com/zhijianliutang/p/2641992.html