RoleManager<TRole> Class

Provides the APIs for managing roles in a persistence store.

Namespace
Microsoft.AspNetCore.Identity
Assemblies
  • Microsoft.AspNetCore.Identity

Syntax

public class RoleManager<TRole> : IDisposable where TRole : class
class Microsoft.AspNetCore.Identity.RoleManager<TRole>

Constructors

RoleManager(Microsoft.AspNetCore.Identity.IRoleStore<TRole>, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Identity.IRoleValidator<TRole>>, Microsoft.AspNetCore.Identity.ILookupNormalizer, Microsoft.AspNetCore.Identity.IdentityErrorDescriber, Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Identity.RoleManager<TRole>>, Microsoft.AspNetCore.Http.IHttpContextAccessor)

Constructs a new instance of Microsoft.AspNetCore.Identity.RoleManager`1.

Arguments:
public RoleManager(IRoleStore<TRole> store, IEnumerable<IRoleValidator<TRole>> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, ILogger<RoleManager<TRole>> logger, IHttpContextAccessor contextAccessor)

Methods

AddClaimAsync(TRole, System.Security.Claims.Claim)

Adds a claim to a role.

Arguments:
  • role (TRole) – The role to add the claim to.
  • claim (System.Security.Claims.Claim) – The claim to add.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>

Returns:

The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation.

public virtual Task<IdentityResult> AddClaimAsync(TRole role, Claim claim)
CreateAsync(TRole)

Creates the specified <em>role</em> in the persistence store.

Arguments:role (TRole) – The role to create.
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation.
public virtual Task<IdentityResult> CreateAsync(TRole role)
DeleteAsync(TRole)

Deletes the specified <em>role</em>.

Arguments:role (TRole) – The role to delete.
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult for the delete.
public virtual Task<IdentityResult> DeleteAsync(TRole role)
Dispose()

Releases all resources used by the role manager.

public void Dispose()
Dispose(System.Boolean)

Releases the unmanaged resources used by the role manager and optionally releases the managed resources.

Arguments:disposing (System.Boolean) – true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing)
FindByIdAsync(System.String)

Finds the role associated with the specified <em>roleId</em> if any.

Arguments:roleId (System.String) – The role ID whose role should be returned.
Return type:System.Threading.Tasks.Task<TRole>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the role associated with the specified <em>roleId</em>
public virtual Task<TRole> FindByIdAsync(string roleId)
FindByNameAsync(System.String)

Finds the role associated with the specified <em>roleName</em> if any.

Arguments:roleName (System.String) – The name of the role to be returned.
Return type:System.Threading.Tasks.Task<TRole>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the role associated with the specified <em>roleName</em>
public virtual Task<TRole> FindByNameAsync(string roleName)
GetClaimsAsync(TRole)

Gets a list of claims associated with the specified <em>role</em>.

Arguments:role (TRole) – The role whose claims should be returned.
Return type:System.Threading.Tasks.Task<System.Collections.Generic.IList<System.Security.Claims.Claim>>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the list of System.Security.Claims.Claims associated with the specified <em>role</em>.
public virtual Task<IList<Claim>> GetClaimsAsync(TRole role)
GetRoleIdAsync(TRole)

Gets the ID of the specified <em>role</em>.

Arguments:role (TRole) – The role whose ID should be retrieved.
Return type:System.Threading.Tasks.Task<System.String>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the ID of the specified <em>role</em>.
public virtual Task<string> GetRoleIdAsync(TRole role)
GetRoleNameAsync(TRole)

Gets the name of the specified <em>role</em>.

Arguments:role (TRole) – The role whose name should be retrieved.
Return type:System.Threading.Tasks.Task<System.String>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the name of the specified <em>role</em>.
public virtual Task<string> GetRoleNameAsync(TRole role)
NormalizeKey(System.String)

Gets a normalized representation of the specified <em>key</em>.

Arguments:key (System.String) – The value to normalize.
Return type:System.String
Returns:A normalized representation of the specified <em>key</em>.
public virtual string NormalizeKey(string key)
RemoveClaimAsync(TRole, System.Security.Claims.Claim)

Removes a claim from a role.

Arguments:
  • role (TRole) – The role to remove the claim from.
  • claim (System.Security.Claims.Claim) – The claim to remove.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>

Returns:

The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation.

public virtual Task<IdentityResult> RemoveClaimAsync(TRole role, Claim claim)
RoleExistsAsync(System.String)

Gets a flag indicating whether the specified <em>roleName</em> exists.

Arguments:roleName (System.String) – The role name whose existence should be checked.
Return type:System.Threading.Tasks.Task<System.Boolean>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing true if the role name exists, otherwise false.
public virtual Task<bool> RoleExistsAsync(string roleName)
SetRoleNameAsync(TRole, System.String)

Sets the name of the specified <em>role</em>.

Arguments:
  • role (TRole) – The role whose name should be set.
  • name (System.String) – The name to set.
Return type:

System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>

Returns:

The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult of the operation.

public virtual Task<IdentityResult> SetRoleNameAsync(TRole role, string name)
ThrowIfDisposed()
protected void ThrowIfDisposed()
UpdateAsync(TRole)

Updates the specified <em>role</em>.

Arguments:role (TRole) – The role to updated.
Return type:System.Threading.Tasks.Task<Microsoft.AspNetCore.Identity.IdentityResult>
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation, containing the Microsoft.AspNetCore.Identity.IdentityResult for the update.
public virtual Task<IdentityResult> UpdateAsync(TRole role)
UpdateNormalizedRoleNameAsync(TRole)

Updates the normalized name for the specified <em>role</em>.

Arguments:role (TRole) – The role whose normalized name needs to be updated.
Return type:System.Threading.Tasks.Task
Returns:The System.Threading.Tasks.Task that represents the asynchronous operation.
public virtual Task UpdateNormalizedRoleNameAsync(TRole role)

Properties

Microsoft.AspNetCore.Identity.RoleManager<TRole>.Logger

Gets the Microsoft.Extensions.Logging.ILogger used to log messages from the manager.

Return type:Microsoft.Extensions.Logging.ILogger
Returns:The Microsoft.Extensions.Logging.ILogger used to log messages from the manager.
protected virtual ILogger Logger { get; set; }
Microsoft.AspNetCore.Identity.RoleManager<TRole>.Roles

Gets an IQueryable collection of Roles if the persistence store is an Microsoft.AspNetCore.Identity.IQueryableRoleStore`1, otherwise throws a System.NotSupportedException.

Return type:System.Linq.IQueryable<TRole>
Returns:An IQueryable collection of Roles if the persistence store is an Microsoft.AspNetCore.Identity.IQueryableRoleStore`1.
public virtual IQueryable<TRole> Roles { get; }
Microsoft.AspNetCore.Identity.RoleManager<TRole>.Store

Gets the persistence store this instance operates over.

Return type:Microsoft.AspNetCore.Identity.IRoleStore<TRole>
Returns:The persistence store this instance operates over.
protected IRoleStore<TRole> Store { get; }
Microsoft.AspNetCore.Identity.RoleManager<TRole>.SupportsQueryableRoles

Gets a flag indicating whether the underlying persistence store supports returning an System.Linq.IQueryable collection of roles.

Return type:System.Boolean
Returns:true if the underlying persistence store supports returning an System.Linq.IQueryable collection of roles, otherwise false.
public virtual bool SupportsQueryableRoles { get; }
Microsoft.AspNetCore.Identity.RoleManager<TRole>.SupportsRoleClaims

Gets a flag indicating whether the underlying persistence store supports System.Security.Claims.Claims for roles.

Return type:System.Boolean
Returns:true if the underlying persistence store supports System.Security.Claims.Claims for roles, otherwise false.
public virtual bool SupportsRoleClaims { get; }