Table of Contents

Class ApplicationUserStore<TUser>

Namespace
Kentico.Membership
Assembly
Kentico.Membership.dll

Implements basic user management operations.

public class ApplicationUserStore<TUser> where TUser : ApplicationUser, new()

Type Parameters

TUser
Inheritance
object
ApplicationUserStore<TUser>
Extension Methods

Constructors

ApplicationUserStore(IMemberInfoProvider, IMemberExternalLoginInfoProvider)

Initializes a new instance of the ApplicationUserStore<TUser>.

public ApplicationUserStore(IMemberInfoProvider memberInfoProvider, IMemberExternalLoginInfoProvider memberExternalLoginInfoProvider)

Parameters

memberInfoProvider IMemberInfoProvider

Provider for MemberInfo management.

memberExternalLoginInfoProvider IMemberExternalLoginInfoProvider

Provider for MemberExternalLoginInfo management.

Exceptions

ArgumentNullException

Thrown when any of the required parameters is null.

Methods

AddLoginAsync(TUser, UserLoginInfo, CancellationToken)

Adds an external Microsoft.AspNetCore.Identity.UserLoginInfo to the specified user.

public Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken)

Parameters

user TUser

The user to add the login to.

login UserLoginInfo

The external Microsoft.AspNetCore.Identity.UserLoginInfo to add to the specified user.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user or login is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

AddToRoleAsync(TUser, string, CancellationToken)

Add the specified user to the named role.

public Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)

Parameters

user TUser

The user to add to the named role.

roleName string

The name of the role to add the user to.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

ArgumentException

Thrown when roleName is null or empty.

InvalidOperationException

Thrown when role is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

CreateAsync(TUser, CancellationToken)

Creates the specified user in the user store.

public Task<IdentityResult> CreateAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user to create.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IdentityResult>

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

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

DeleteAsync(TUser, CancellationToken)

Deletes the user.

public Task<IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

User.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IdentityResult>

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

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

Dispose()

Performs tasks to dispose the user store.

public void Dispose()

Dispose(bool)

Disposes the user store.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Describes whether or not should the managed resources be disposed.

FindByEmailAsync(string, CancellationToken)

Gets the user, if any, associated with the specified, normalized email address.

public Task<TUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken)

Parameters

normalizedEmail string

The normalized email address to return the user for.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<TUser>

The System.Threading.Tasks.Task<TResult> containing the results of the asynchronous lookup operation, the user if any associated with the specified normalized email address.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

FindByIdAsync(int, CancellationToken)

Finds and returns a user, if any, who has the specified userId.

public Task<TUser> FindByIdAsync(int userId, CancellationToken cancellationToken)

Parameters

userId int

The user identifier.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<TUser>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the user matching the specified userId if it exists.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

FindByIdAsync(string, CancellationToken)

Finds and returns a user, if any, who has the specified userId.

public Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken)

Parameters

userId string

The user ID to search for.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<TUser>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the user matching the specified userId if it exists.

Exceptions

ArgumentException

Thrown when userId is empty or non-integer.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

FindByLoginAsync(string, string, CancellationToken)

Retrieves the user associated with the specified login provider and login provider key.

public Task<TUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)

Parameters

loginProvider string

The login provider who provided the providerKey.

providerKey string

The key provided by the loginProvider to identify a user.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<TUser>

The System.Threading.Tasks.Task<TResult> for the asynchronous operation, containing the user, if any which matched the specified login provider and key.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

FindByNameAsync(string, CancellationToken)

Finds and returns a user, if any, who has the specified normalized user name.

public Task<TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)

Parameters

normalizedUserName string

The normalized user name to search for.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<TUser>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the user matching the specified normalizedUserName if it exists.

Exceptions

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetEmailAsync(TUser, CancellationToken)

Gets the email address for the specified user.

public Task<string> GetEmailAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email should be returned.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> containing the results of the asynchronous operation, the email address for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetEmailConfirmedAsync(TUser, CancellationToken)

Gets a flag indicating whether the email address for the specified user has been verified, true if the email address is verified otherwise false.

public Task<bool> GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email confirmation status should be returned.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<bool>

The System.Threading.Tasks.Task<TResult> containing the results of the asynchronous operation, a flag indicating whether the email address for the specified user has been confirmed or not.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetLoginsAsync(TUser, CancellationToken)

Retrieves the associated logins for the specified user.

public Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose associated logins to retrieve.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IList<UserLoginInfo>>

The System.Threading.Tasks.Task<TResult> for the asynchronous operation, containing a list of Microsoft.AspNetCore.Identity.UserLoginInfo for the specified user, if any.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetNormalizedEmailAsync(TUser, CancellationToken)

Returns the normalized email for the specified user.

public Task<string> GetNormalizedEmailAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email address to retrieve.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> containing the results of the asynchronous lookup operation, the normalized email address if any associated with the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetNormalizedUserNameAsync(TUser, CancellationToken)

Gets the normalized user name for the specified user.

public Task<string> GetNormalizedUserNameAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose normalized name should be retrieved.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the normalized user name for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetPasswordHashAsync(TUser, CancellationToken)

Gets the password hash for the specified user.

public Task<string> GetPasswordHashAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose password hash to retrieve.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, returning the password hash for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

InvalidOperationException

Thrown when user is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetRolesAsync(TUser, CancellationToken)

Gets a list of role names the specified user belongs to.

public Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose role names to retrieve.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IList<string>>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing a list of role names.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetSecurityStampAsync(TUser, CancellationToken)

Get the security stamp for the specified user.

public Task<string> GetSecurityStampAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose security stamp should be retrieved.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the security stamp for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetUserIdAsync(TUser, CancellationToken)

Gets the user identifier for the specified user.

public Task<string> GetUserIdAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose identifier should be retrieved.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the identifier for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetUserNameAsync(TUser, CancellationToken)

Gets the user name for the specified user.

public Task<string> GetUserNameAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user whose name should be retrieved.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing the name for the specified user.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

GetUsersInRoleAsync(string, CancellationToken)

Returns a list of users who are members of the named role.

public Task<IList<TUser>> GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken)

Parameters

roleName string

The name of the role whose membership should be returned.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IList<TUser>>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing a list of users who are in the named role.

Exceptions

ArgumentException

Thrown when roleName is null or empty.

InvalidOperationException

Thrown when role is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

HasPasswordAsync(TUser, CancellationToken)

Gets a flag indicating whether the specified user has a password.

public Task<bool> HasPasswordAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user to return a flag for, indicating whether they have a password or not.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<bool>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, returning true if the specified user has a password; otherwise false.

Exceptions

ArgumentNullException

Thrown when user is null.

InvalidOperationException

Thrown when user is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

IsInRoleAsync(TUser, string, CancellationToken)

Returns a flag indicating whether the specified user is a member of the given named role.

public Task<bool> IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)

Parameters

user TUser

The user whose role membership should be checked.

roleName string

The name of the role to be checked.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<bool>

The System.Threading.Tasks.Task<TResult> that represents the asynchronous operation, containing a flag indicating whether the specified user is a member of the named role.

Exceptions

ArgumentNullException

Thrown when user is null.

ArgumentException

Thrown when roleName is null or empty.

InvalidOperationException

Thrown when role is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

RemoveFromRoleAsync(TUser, string, CancellationToken)

Remove the specified user from the named role.

public Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken)

Parameters

user TUser

The user to remove the named role from.

roleName string

The name of the role to remove.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

ArgumentException

Thrown when roleName is null or empty.

InvalidOperationException

Thrown when role is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

RemoveLoginAsync(TUser, string, string, CancellationToken)

Attempts to remove the provided login information from the specified user. and returns a flag indicating whether the removal succeed or not.

public Task RemoveLoginAsync(TUser user, string loginProvider, string providerKey, CancellationToken cancellationToken)

Parameters

user TUser

The user to remove the login information from.

loginProvider string

The login provide whose information should be removed.

providerKey string

The key given by the external login provider for the specified user.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetEmailAsync(TUser, string, CancellationToken)

Sets the email address for a user.

public Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email should be set.

email string

The email to set.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetEmailConfirmedAsync(TUser, bool, CancellationToken)

Sets the flag indicating whether the specified user's email address has been confirmed or not.

public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email confirmation status should be set.

confirmed bool

A flag indicating if the email address has been confirmed, true if the address is confirmed otherwise false.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task representing the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetNormalizedEmailAsync(TUser, string, CancellationToken)

Sets the normalized email for the specified user.

public Task SetNormalizedEmailAsync(TUser user, string normalizedEmail, CancellationToken cancellationToken)

Parameters

user TUser

The user whose email address to set.

normalizedEmail string

The normalized email to set for the specified user.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task representing the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetNormalizedUserNameAsync(TUser, string, CancellationToken)

Sets the given normalized name for the specified user.

public Task SetNormalizedUserNameAsync(TUser user, string normalizedName, CancellationToken cancellationToken)

Parameters

user TUser

The user whose name should be set.

normalizedName string

The normalized name to set.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetPasswordHashAsync(TUser, string, CancellationToken)

Sets the password hash for the specified user.

public Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken)

Parameters

user TUser

The user whose password hash to set.

passwordHash string

The password hash to set.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetSecurityStampAsync(TUser, string, CancellationToken)

Sets the provided security stamp for the specified user.

public Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken)

Parameters

user TUser

The user whose security stamp should be set.

stamp string

The security stamp to set.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

SetUserNameAsync(TUser, string, CancellationToken)

Sets the given userName for the specified user.

public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken)

Parameters

user TUser

The user whose name should be set.

userName string

The user name to set.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

The System.Threading.Tasks.Task that represents the asynchronous operation.

Exceptions

ArgumentNullException

Thrown when user is null.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.

ThrowIfDisposed()

Throws if this class has been disposed.

protected void ThrowIfDisposed()

UpdateAsync(TUser, CancellationToken)

Updates the specified user in the user store.

public Task<IdentityResult> UpdateAsync(TUser user, CancellationToken cancellationToken)

Parameters

user TUser

The user to update.

cancellationToken CancellationToken

The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<IdentityResult>

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

Exceptions

ArgumentNullException

Thrown when user is null.

InvalidOperationException

Thrown when user is not found.

OperationCanceledException

Thrown when cancellationToken is canceled.

ObjectDisposedException

Thrown when the store object has been disposed.