November Happy Hour will be moved to Thursday December 5th.

Class WindowsRoleProvider

Role provider to be used together with WindowsMembershipProvider. Note that this provider does not really interact with Windows groups, but simply stores group information in the database. The database information is then updated by the WindowsMembershipProvider.

Inheritance
System.Object
WindowsRoleProvider
Namespace: EPiServer.Security
Assembly: EPiServer.dll
Version: 10.10.4
Syntax
[ProviderCapability((ProviderActions)0)]
public class WindowsRoleProvider : RoleProvider

Constructors

WindowsRoleProvider()

Initializes a new instance of the WindowsRoleProvider class.

Declaration
public WindowsRoleProvider()

Properties

ApplicationName

Gets or sets the name of the application to store and retrieve role information for.

Declaration
public override string ApplicationName { get; set; }
Property Value
Type Description
System.String

The name of the application.

Remarks

In the current implementation, the ApplicationName is ignored.

Methods

AddUsersToRoles(String[], String[])

Not supported by this provider. Adds the specified user names to the specified roles for the configured applicationName.

Declaration
public override void AddUsersToRoles(string[] usernames, string[] roleNames)
Parameters
Type Name Description
System.String[] usernames

A string array of user names to be added to the specified roles.

System.String[] roleNames

A string array of the role names to add the specified user names to.

CreateRole(String)

Adds a new role to the data source for the configured applicationName.

Declaration
public override void CreateRole(string roleName)
Parameters
Type Name Description
System.String roleName

The name of the role to create.

DeleteRole(String, Boolean)

Removes a role from the data source for the configured applicationName.

Declaration
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
Parameters
Type Name Description
System.String roleName

The name of the role to delete.

System.Boolean throwOnPopulatedRole

If true, throw an exception if roleName has one or more members and do not delete roleName.

Returns
Type Description
System.Boolean

true if the role was successfully deleted; otherwise, false.

FindUsersInRole(String, String)

Gets an array of user names in a role where the user name contains the specified user name to match.

Declaration
public override string[] FindUsersInRole(string roleName, string usernameToMatch)
Parameters
Type Name Description
System.String roleName

The role to search in.

System.String usernameToMatch

The user name to search for.

Returns
Type Description
System.String[]

A string array containing the names of all the users where the user name matches usernameToMatch and the user is a member of the specified role.

Remarks

The usernameToMatch can handle wildcard search according to the rules for the SQL LIKE operator. I e setting usernameToMatch to "adam%" will match any username staring with adam.

GetAllRoles()

Gets a list of all the roles for the configured applicationName.

Declaration
public override string[] GetAllRoles()
Returns
Type Description
System.String[]

A string array containing the names of all the roles stored in the data source for the configured applicationName.

GetRolesForUser(String)

Gets a list of the roles that a specified user is in for the configured applicationName.

Declaration
public override string[] GetRolesForUser(string username)
Parameters
Type Name Description
System.String username

The user to return a list of roles for.

Returns
Type Description
System.String[]

A string array containing the names of all the roles that the specified user is in for the configured applicationName.

GetUsersInRole(String)

Gets a list of users in the specified role for the configured applicationName.

Declaration
public override string[] GetUsersInRole(string roleName)
Parameters
Type Name Description
System.String roleName

The name of the role to get the list of users for.

Returns
Type Description
System.String[]

A string array containing the names of all the users who are members of the specified role for the configured applicationName.

Initialize(String, NameValueCollection)

Initializes the provider.

Declaration
public override void Initialize(string name, NameValueCollection config)
Parameters
Type Name Description
System.String name

The friendly name of the provider.

System.Collections.Specialized.NameValueCollection config

A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.

Exceptions
Type Condition
System.ArgumentNullException

The name of the provider is null.

System.InvalidOperationException

An attempt is made to call System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection) on a provider after the provider has already been initialized.

System.ArgumentException

The name of the provider has a length of zero.

IsUserInRole(String, String)

Gets a value indicating whether the specified user is in the specified role for the configured applicationName.

Declaration
public override bool IsUserInRole(string username, string roleName)
Parameters
Type Name Description
System.String username

The user name to search for.

System.String roleName

The role to search in.

Returns
Type Description
System.Boolean

true if the specified user is in the specified role for the configured applicationName; otherwise, false.

RemoveUsersFromRoles(String[], String[])

Not supported by this provider. Removes the specified user names from the specified roles for the configured applicationName.

Declaration
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
Parameters
Type Name Description
System.String[] usernames

A string array of user names to be removed from the specified roles.

System.String[] roleNames

A string array of role names to remove the specified user names from.

RoleExists(String)

Gets a value indicating whether the specified role name already exists in the role data source for the configured applicationName.

Declaration
public override bool RoleExists(string roleName)
Parameters
Type Name Description
System.String roleName

The name of the role to search for in the data source.

Returns
Type Description
System.Boolean

true if the role name already exists in the data source for the configured applicationName; otherwise, false.

Remarks

Note that this method only checks if the given roleName is present in the database. The Windows group may exist, but if no user belonging to that group has logged on, this method will return false.

Extension Methods