请注意:此 API 现在已过时。
Use the new SPRoleDefinition and SPRoleAssignment classes instead, to define roles and to assign users to them. For more information, see Changes in the Authorization Object Model. (In Windows SharePoint Services 2.0, SPRole represented a site group and is maintained for backward compatibility.)
继承层次结构
System.Object
Microsoft.SharePoint.SPMember
Microsoft.SharePoint.SPRole
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
<ObsoleteAttribute("Use the SPRoleDefinition class instead")> _
Public Class SPRole _
Inherits SPMember
用法
Dim instance As SPRole
[ObsoleteAttribute("Use the SPRoleDefinition class instead")]
public class SPRole : SPMember
备注
使用SPUser、 SPGroup或SPWeb类的Roles属性可返回SPRoleCollection对象代表角色或角色定义的用户、 组或网站的集合。使用索引器从集合中返回单个角色。例如,如果集合分配给名为collRoles的变量中,使用 C# 中的collRoles[index]或collRoles(index)在 Visual Basic 中,其中index是集合中的角色的索引号,或者该角色的显示名称。
每个角色或角色定义具有唯一成员 ID (ID属性),具有与该成员资格,关联的权限以及可以由SPMember对象表示。
下面的示例将一个角色分配给SPMember对象。
Dim myMember As SPMember = site.Roles("Role_Name")
SPMember oMember = oWebsite.Roles["Role_Name"];
若要执行任何会影响服务器场中的所有 Web 应用程序设置的管理任务,用户必须是 SharePoint 管理员组的成员。
不能修改或删除的Administrator和Guest角色。
For general information about roles and security, see Security, Users, and Groups in Windows SharePoint Services.
有关在SharePoint Foundation中可用的默认角色的信息,请参阅SPRoleType枚举。
示例
下面的代码示例从网站下的所有子网站中的一个角色中删除指定的用户。
Dim site As SPWeb =
SPContext.Current.Site.AllWebs("Site_Name")
Dim subSites As SPWebCollection = site.Webs
Dim user As SPUser = site.Users("User_Name")
Dim subSite As SPWeb
For Each subSite In subSites
Dim role As SPRole = subSite.Roles("Role_Name")
role.RemoveUser(user)
Next subSite
using(SPWeb oParentWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
{
SPWebCollection collWebsites = oParentWebsite.Webs;
SPUser oUser = oParentWebsite.Users["User_Name"];
foreach (SPWeb oWebsite in collWebsites)
{
SPRole oRole = oWebsite.Roles["Role_Name"];
oRole.RemoveUser(oUser);
oWebsite.Dispose();
}
}
备注
Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.
线程安全性
该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。