Try our conversational search powered by Generative AI!

Class VirtualRoleHelper

Helps manage roles, virtual roles and the repository

Inheritance
System.Object
VirtualRoleHelper
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Security
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public class VirtualRoleHelper

Constructors

VirtualRoleHelper(VirtualRoleRepository<VirtualRoleProviderBase>, RoleProvider)

Initializes a new instance of the VirtualRoleHelper class.

Declaration
public VirtualRoleHelper(VirtualRoleRepository<VirtualRoleProviderBase> virtualRoleRepository, RoleProvider roleProvider)
Parameters
Type Name Description
VirtualRoleRepository<VirtualRoleProviderBase> virtualRoleRepository
System.Web.Security.RoleProvider roleProvider

Properties

Repository

The repository that contains all registered virtual roles

Declaration
public VirtualRoleRepository<VirtualRoleProviderBase> Repository { get; }
Property Value
Type Description
VirtualRoleRepository<VirtualRoleProviderBase>

Methods

GetAllRoles()

Gets all virtual roles and all roles defined by the Role provider.

Declaration
public IEnumerable<string> GetAllRoles()
Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

A string array with all role names.

Remarks

If you want to get a list of all roles, both from the Roles provider and virtual roles, use this method since it will filter out any duplicates caused by overloading role names from virtual roles. I e if you have a virtual role named "Administrators" and Roles.GetAllRoles() contains an entry named "Administrators" the final array returned by this method will only contain a single reference to the "Administrators" name.

GetAllRolesForUser(String)

Gets all available roles for a user.

Declaration
public IEnumerable<string> GetAllRolesForUser(string username)
Parameters
Type Name Description
System.String username

The username.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

An enumberable of strings with the names of all available roles for the user, regardless if she is a member of the role or not.

GetAllVirtualRoles()

Get a list of all virtual roles.

Declaration
public IEnumerable<string> GetAllVirtualRoles()
Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

A string array with the virtual role names.

GetRoleNameForClass(Type)

Gets the virtual role name for the specified class (if many exists you may receive any of them)

Declaration
public string GetRoleNameForClass(Type classType)
Parameters
Type Name Description
System.Type classType

Type of the class.

Returns
Type Description
System.String

The role name.

IsPrincipalInVirtualRole(IPrincipal, String, Object)

Determines whether the specified principal is in the virtual role

Declaration
public bool IsPrincipalInVirtualRole(IPrincipal principal, string virtualRole, object context)
Parameters
Type Name Description
System.Security.Principal.IPrincipal principal

The principal.

System.String virtualRole

The role.

System.Object context

The context of the request

Returns
Type Description
System.Boolean

true if the specified principal is in the virtual role; otherwise, false.

SearchRoles(String)

Find virtual roles and roles defined by the Role provider.

Declaration
public IEnumerable<string> SearchRoles(string query)
Parameters
Type Name Description
System.String query

Query to find roles in.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

A list of roles that match the roleName

Remarks

Matching of role names is simply a substring check - if the role contains the string passed in roleName anywhere in the string, it is considered a match. A Null or empty roleName will return all roles.

If you want to get a list of roles from the Roles provider and virtual roles, use this method since it will filter out any duplicates caused by overloading role names from virtual roles. I e if you have a virtual role named "Administrators" and Roles.GetAllRoles() contains an entry named "Administrators" the final enumerator returned by this method will only contain a single reference to the "Administrators" name.

Extension Methods