Store 没有实现 IUserLockoutStore<TUser> [英] Store does not implement IUserLockoutStore<TUser>

查看:16
本文介绍了Store 没有实现 IUserLockoutStore<TUser>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我需要的功能为 asp.net Identity 2.0 实现自己的 DAL.我不需要帐户锁定功能.但是当我尝试打电话时

I'm trying to implement own DAL for asp.net Identity 2.0 with functionality that I need. I don't need Account Lockout functionality. But When I try to call

var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false);

我得到 System.NotSupportedException:Store 没有实现 IUserLockoutStore.

那么,如果我不需要它,我为什么要实现 IUserLockoutStore?

So why should I need to implement IUserLockoutStore if I dont need it?

推荐答案

看到这个答案:当实现你自己的 IUserStore 时,是可选的"类上的接口实际上是可选的吗?

您需要欺骗或覆盖您尝试在商店中调用的方法,以实现不使用可选"锁定商店的方法.

You will need to trick or override the method you are trying to call in your store to implement one that does not use the "optional" lockout store.

您可能会惊讶地发现您还需要为二要素实现可选"接口.除非您确实有两个因素的方法,否则请使用以下相同的答案.

You may be unpleasantly surprised to find that you also need to implement the "optional" interface for two-factor. Use the same answer below to do so unless you do have a means of two-factor.

首先,这是默认实现:

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;
        }

一个答案:创建无用的商店.

One answer: create useless stores.

    #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
}

另一种解决方案:覆盖只是不使用它.

Another solution: override to just not use it.

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/https://github.com/aspnet/AspNetIdentity/blob/master/src/Microsoft.AspNet.Identity.Owin/SignInManager.cs

这篇关于Store 没有实现 IUserLockoutStore&lt;TUser&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆