RoleManager<TRole> Class

Summary

Provides the APIs for managing roles in a persistence store.

Syntax

public class RoleManager<TRole> : IDisposable where TRole : class

GitHub

View on GitHub

class Microsoft.AspNet.Identity.RoleManager<TRole>

Constructors

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

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

Arguments:
  • store (Microsoft.AspNet.Identity.IRoleStore{{TRole}}) – The persistence store the manager will operate over.
  • roleValidators (System.Collections.Generic.IEnumerable{Microsoft.AspNet.Identity.IRoleValidator}) – A collection of validators for roles.
  • keyNormalizer (Microsoft.AspNet.Identity.ILookupNormalizer) – The normalizer to use when normalizing role names to keys.
  • errors (Microsoft.AspNet.Identity.IdentityErrorDescriber) – The Microsoft.AspNet.Identity.IdentityErrorDescriber used to provider error messages.
  • logger (ILogger{Microsoft.AspNet.Identity.RoleManager`1}) – The logger used to log messages, warnings and errors.
  • contextAccessor (IHttpContextAccessor) – The accessor used to access the HttpContext.
public RoleManager(IRoleStore<TRole> store, IEnumerable<IRoleValidator> roleValidators, ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, ILogger<RoleManager<TRole>> logger, IHttpContextAccessor contextAccessor)

Methods

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

Adds a claim to a role, as an asynchronous operation.

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.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the <see cref=”T:Microsoft.AspNet.Identity.IdentityResult” /> of the operation.

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

Creates the specified role in the persistence store, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role to create.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation.

public virtual Task<IdentityResult> CreateAsync(TRole role)
DeleteAsync(TRole)

Deletes the specified role, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role to delete.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the <see cref=”T:Microsoft.AspNet.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 roleId if any, as an asynchronous operation.

Arguments:
  • roleId (System.String) – The role ID whose role should be returned.
Return type:

System.Threading.Tasks.Task{{TRole}}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the role associated with the specified <paramref name=”roleId” />

public virtual Task<TRole> FindByIdAsync(string roleId)
FindByNameAsync(System.String)

Finds the role associated with the specified roleName if any, as an asynchronous operation.

Arguments:
  • roleName (System.String) – The name of the role to be returned.
Return type:

System.Threading.Tasks.Task{{TRole}}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the role associated with the specified <paramref name=”roleName” />

public virtual Task<TRole> FindByNameAsync(string roleName)
GetClaimsAsync(TRole)

Gets a list of claims associated with the specified role, as an asynchronous operation.

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 <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the list of <see cref=”T:System.Security.Claims.Claim” />s associated with the specified <paramref name=”role” />.

public virtual Task<IList<Claim>> GetClaimsAsync(TRole role)
GetRoleIdAsync(TRole)

Gets the ID of the specified role, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role whose ID should be retrieved.
Return type:

System.Threading.Tasks.Task{System.String}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the ID of the specified <paramref name=”role” />.

public virtual Task<string> GetRoleIdAsync(TRole role)
GetRoleNameAsync(TRole)

Gets the name of the specified role, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role whose name should be retrieved.
Return type:

System.Threading.Tasks.Task{System.String}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the name of the specified <paramref name=”role” />.

public virtual Task<string> GetRoleNameAsync(TRole role)
NormalizeKey(System.String)

Gets a normalized representation of the specified key.

Arguments:
  • key (System.String) – The value to normalize.
Return type:

System.String

Returns:

A normalized representation of the specified <paramref name=”key” />.

public virtual string NormalizeKey(string key)
RemoveClaimAsync(TRole, System.Security.Claims.Claim)

Removes a claim from a role, as an asynchronous operation.

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

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the <see cref=”T:Microsoft.AspNet.Identity.IdentityResult” /> of the operation.

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

Gets a flag indicating whether the specified roleName exists, as an asynchronous operation.

Arguments:
  • roleName (System.String) – The role name whose existence should be checked.
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

The <see cref=”T: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 role, as an asynchronous operation.

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

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the <see cref=”T:Microsoft.AspNet.Identity.IdentityResult” /> of the operation.

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

Updates the specified role, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role to updated.
Return type:

System.Threading.Tasks.Task{Microsoft.AspNet.Identity.IdentityResult}

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation, containing the <see cref=”T:Microsoft.AspNet.Identity.IdentityResult” /> for the update.

public virtual Task<IdentityResult> UpdateAsync(TRole role)
UpdateNormalizedRoleNameAsync(TRole)

Updates the normalized name for the specified role, as an asynchronous operation.

Arguments:
  • role ({TRole}) – The role whose normalized name needs to be updated.
Return type:

System.Threading.Tasks.Task

Returns:

The <see cref=”T:System.Threading.Tasks.Task” /> that represents the asynchronous operation.

public virtual Task UpdateNormalizedRoleNameAsync(TRole role)

Properties

Logger()

Gets the ILogger used to log messages from the manager.

Return type:ILogger
protected virtual ILogger Logger { get; set; }
Roles()

Gets an IQueryable collection of Roles if the persistence store is an IQueryableRoleStore, otherwise throws a System.NotSupportedException.

Return type:System.Linq.IQueryable{{TRole}}
public virtual IQueryable<TRole> Roles { get; }
Store()

Gets the persistence store this instance operates over.

Return type:Microsoft.AspNet.Identity.IRoleStore{{TRole}}
protected IRoleStore<TRole> Store { get; }
SupportsQueryableRoles()

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

Return type:System.Boolean
public virtual bool SupportsQueryableRoles { get; }
SupportsRoleClaims()

Gets a flag indicating whether the underlying persistence store supports :dn:ref:`System.Security.Claims.Claim`s for roles.

Return type:System.Boolean
public virtual bool SupportsRoleClaims { get; }