Asp.net mvc 5 门店未实施IUSERLOCKOUNTORE<;TUser>;
我正在尝试为asp.net Identity 2.0实现自己的DAL,并提供所需的功能。我不需要帐户锁定功能。但是当我试着打电话的时候Asp.net mvc 5 门店未实施IUSERLOCKOUNTORE<;TUser>;,asp.net-mvc-5,asp.net-identity,Asp.net Mvc 5,Asp.net Identity,我正在尝试为asp.net Identity 2.0实现自己的DAL,并提供所需的功能。我不需要帐户锁定功能。但是当我试着打电话的时候 var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false); 我得到系统。不支持异常:存储区不实现IUserLockoutStore。 那么,如果我不需要,为什么我需要实现IUs
var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false);
我得到系统。不支持异常:存储区不实现IUserLockoutStore。
那么,如果我不需要,为什么我需要实现IUserLockoutStore呢 看看这个答案:
您需要欺骗或覆盖您试图在存储中调用的方法,以实现一个不使用“可选”锁定存储的方法
您可能会惊讶地发现,您还需要为两个因素实现“可选”接口。使用下面相同的答案,除非你有两个因素的方法
不过,首先,这里是默认实现:
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;
}
公共虚拟异步任务密码签名同步(字符串用户名、字符串密码、bool ispersist、bool shouldllockout)
{
...
if(wait UserManager.IsLockedOutAsync(user.Id).WithCurrentCulture())
{
返回信号status.LockedOut;
}
if(等待UserManager.CheckPasswordAsync(用户,密码).WithCurrentCulture())
{
return wait SignInOrTwoFactor(用户,isPersistent).WithCurrentCulture();
}
...
返回信号状态失败;
}
一个答案是:创建无用的商店
#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
}
#地区锁店
公共任务GetAccessFailedCountAsync(MyUser)
{
抛出新的NotImplementedException();
}
公共任务GetLockoutEnableAsync(MyUser)
{
返回Task.Factory.StartNew(()=>false);
}
公共任务GetLockoutEndDateAsync(MyUser)
{
抛出新的NotImplementedException();
}
公共任务IncrementAccessFailedCountAsync(MyUser)
{
抛出新的NotImplementedException();
}
公共任务ResetAccessFailedCountAsync(MyUser)
{
抛出新的NotImplementedException();
}
公共任务SetLockoutEnabledAsync(MyUser用户,启用bool)
{
抛出新的NotImplementedException();
}
公共任务SetLockoutEndDateAsync(MyUser用户,DateTimeOffset lockoutEnd)
{
抛出新的NotImplementedException();
}
#端区
}
另一个解决方案是:重写以不使用它
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;
}
公共虚拟异步任务密码签名同步(字符串用户名、字符串密码、bool ispersist、bool shouldllockout)
{
...
if(false)
{
返回信号status.LockedOut;
}
if(等待UserManager.CheckPasswordAsync(用户,密码).WithCurrentCulture())
{
return wait SignInOrTwoFactor(用户,isPersistent).WithCurrentCulture();
}
...
返回信号状态失败;
}
cf/末尾的链接不再工作。您可以更新吗?死链接对任何人都没有帮助。@LazyCoder将链接更改为引用默认
SignInManager的实现。您可以使用Task。FromResult(false)
代替启动新任务感谢您的解释,它很糟糕,但一旦你试图以任何方式定制它,它很快就会变成强制性的。