RoleProvider 类


定义 ASP.NET 为使用自定义角色提供程序提供角色管理服务而实现的协定。Defines the contract that ASP.NET implements to provide role-management services using custom role providers.

public ref class RoleProvider abstract : System::Configuration::Provider::ProviderBase
public abstract class RoleProvider : System.Configuration.Provider.ProviderBase
type RoleProvider = class
    inherit ProviderBase
Public MustInherit Class RoleProvider
Inherits ProviderBase


ASP.NET 角色管理旨在使你能够轻松地为 ASP.NET 应用程序使用多个不同的角色提供程序。ASP.NET role management is designed to enable you to easily use a number of different role providers for your ASP.NET applications. 您可以使用 .NET Framework 附带的提供的角色提供程序, 也可以实现您自己的提供程序。You can use the supplied role providers that are included with the .NET Framework, or you can implement your own provider.

实现自定义角色提供程序时, 需要继承RoleProvider抽象类。When implementing a custom role provider, you are required to inherit the RoleProvider abstract class.

创建自定义角色提供程序的主要原因有两个。There are two primary reasons for creating a custom role provider.

  • 您需要将角色信息存储在 .NET Framework 中包含的角色提供程序不支持的数据源中, 如 FoxPro 数据库、Oracle 数据库或其他数据源。You need to store role information in a data source that is not supported by the role providers included with the .NET Framework, such as a FoxPro database, an Oracle database, or other data sources.

  • 需要使用与 .NET Framework 附带的提供程序所使用的数据库架构不同的数据库架构来管理角色信息。You need to manage role information using a database schema that is different from the database schema used by the providers that ship with the .NET Framework. 这种情况的一个常见示例是公司或网站的 SQL Server 数据库中已存在的角色数据。A common example of this would be role data that already exists in a SQL Server database for a company or Web site.



初始化 RoleProvider 类的新实例。Initializes a new instance of the RoleProvider class.



获取或设置要存储和检索其角色信息的应用程序的名称。Gets or sets the name of the application to store and retrieve role information for.


获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)


AddUsersToRoles(String[], String[])

向配置的 applicationName 的指定角色添加指定的用户名。Adds the specified user names to the specified roles for the configured applicationName.


在数据源中为已配置的 applicationName 添加一个新角色。Adds a new role to the data source for the configured applicationName.

DeleteRole(String, Boolean)

从数据源中移除已配置的 applicationName 的角色。Removes a role from the data source for the configured applicationName.


确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
FindUsersInRole(String, String)

获取属于某个角色且与指定的用户名相匹配的用户名的数组。Gets an array of user names in a role where the user name contains the specified user name to match.


获取已配置的 applicationName 的所有角色的列表。Gets a list of all the roles for the configured applicationName.


用作默认哈希函数。Serves as the default hash function.

(继承自 Object)

获取指定用户对于已配置的 applicationName 所属于的角色的列表。Gets a list of the roles that a specified user is in for the configured applicationName.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

获取属于已配置的 applicationName 的指定角色的用户的列表。Gets a list of users in the specified role for the configured applicationName.

Initialize(String, NameValueCollection)

初始化配置生成器。Initializes the configuration builder.

(继承自 ProviderBase)
IsUserInRole(String, String)

获取一个值,指示指定用户是否属于已配置的 applicationName 的指定角色。Gets a value indicating whether the specified user is in the specified role for the configured applicationName.


创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
RemoveUsersFromRoles(String[], String[])

移除已配置的 applicationName 的指定角色中的指定用户名。Removes the specified user names from the specified roles for the configured applicationName.


获取一个值,该值指示指定角色名是否已存在于已配置的 applicationName 的角色数据源中。Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName.


返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)