Vai a questa risposta: When implementing your own IUserStore, are the "optional" interfaces on the class actually optional?
Avrete bisogno di ingannare o sovrascrivere il metodo che si sta tentando di chiamare nel tuo negozio per implementare uno che non utilizza il negozio di blocco "optional".
Potrebbe essere spiacevolmente sorpreso scoprire che è anche necessario implementare l'interfaccia "opzionale" per due fattori. Usa la stessa risposta qui sotto per farlo, a meno che tu non abbia un mezzo a due fattori.
Prima, però, ecco l'implementazione di default:
public virtual async Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
{
...
if (await UserManager.IsLockedOutAsync(user.Id).WithCurrentCulture())
{
return SignInStatus.LockedOut;
}
if (await UserManager.CheckPasswordAsync(user, password).WithCurrentCulture())
{
return await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture();
}
...
return SignInStatus.Failure;
}
Una risposta: creare negozi inutili.
#region LockoutStore
public Task<int> GetAccessFailedCountAsync(MyUser user)
{
throw new NotImplementedException();
}
public Task<bool> GetLockoutEnabledAsync(MyUser user)
{
return Task.Factory.StartNew<bool>(() => false);
}
public Task<DateTimeOffset> GetLockoutEndDateAsync(MyUser user)
{
throw new NotImplementedException();
}
public Task<int> IncrementAccessFailedCountAsync(MyUser user)
{
throw new NotImplementedException();
}
public Task ResetAccessFailedCountAsync(MyUser user)
{
throw new NotImplementedException();
}
public Task SetLockoutEnabledAsync(MyUser user, bool enabled)
{
throw new NotImplementedException();
}
public Task SetLockoutEndDateAsync(MyUser user, DateTimeOffset lockoutEnd)
{
throw new NotImplementedException();
}
#endregion
}
Un'altra soluzione: ignorare semplicemente non utilizzarlo.
public virtual async Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
{
...
if (false)
{
return SignInStatus.LockedOut;
}
if (await UserManager.CheckPasswordAsync(user, password).WithCurrentCulture())
{
return await SignInOrTwoFactor(user, isPersistent).WithCurrentCulture();
}
...
return SignInStatus.Failure;
}
cf/http://eliot-jones.com/Code/asp-identity/MyUserStore.cs
link alla fine non funziona più. Puoi aggiornare? – Vinigas