Class VirtualRoles
Handles the virtual role configuration and role checks for registered providers.
Inheritance
Inherited Members
Namespace: EPiServer.Security
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7Syntax
public class VirtualRoles
Constructors
VirtualRoles()
Declaration
public VirtualRoles()
Properties
IsReplacePrincipal
Gets a value indicating whether we will replace the current principal with a VirtualRolePrincipal.
Declaration
public static bool IsReplacePrincipal { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Methods
GetAllRoles()
Gets all virtual roles and all roles defined by the Role provider.
Declaration
public static string[] GetAllRoles()
Returns
Type | Description |
---|---|
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 static string[] GetAllRolesForUser(string username)
Parameters
Type | Name | Description |
---|---|---|
System.String | username | The username. |
Returns
Type | Description |
---|---|
System.String[] | A string array 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 static string[] GetAllVirtualRoles()
Returns
Type | Description |
---|---|
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 static 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 static 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 |
|
SearchRoles(String)
Search in virtual roles and roles defined by the Role provider.
Declaration
public static IEnumerable<string> SearchRoles(string query)
Parameters
Type | Name | Description |
---|---|---|
System.String | query | The role to find. |
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.