当实现自己的IUserStore,是"可选"在类接口实际上是可选的? [英] When implementing your own IUserStore, are the "optional" interfaces on the class actually optional?

查看:214
本文介绍了当实现自己的IUserStore,是"可选"在类接口实际上是可选的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与微软的Asp.Net身份Framework版本2的工作,和我实现我自己的IUserStore。我的新类 MyUserStore 实施 IUserStore< MyUserClass,INT> 界面和 IUserPasswordStore< MyUserClass ,INT> ,而这一点正是需要用的UserManager&LT使用它; MyUserClass,INT> 类。或者说,至少这是我从阅读喜欢的这个

I'm working with Microsoft's Asp.Net Identity framework version 2, and am implementing my own IUserStore. My new class MyUserStore implements the IUserStore<MyUserClass,int> interface and the IUserPasswordStore<MyUserClass,int>, which is what is required to use it with the UserManager<MyUserClass,int> class. Or at least that's what I gathered from reading tutorials like this:

的身份系统所需的接口一个是IUserStore - 斯科特 - 阿伦

"The one required interface in the identity system is IUserStore" - Scott Allen

不过,这似乎并不当我运行code是这种情况。

But this doesn't seem to be the case when I run the code.

我初始化我的经理:

var uMan= new UserManager<MyUserClass, int>(new MyUserStore()); 
var sMan = new SignInManager<MyUserClass, int>(uMan,authCtxFromOwin);

和执行sMan.PasswordSignIn(...)的SignInManager的时候,不管是什么,该SignInManager总是依赖于可选接口的UserManager运行的功能。下面是从SignInManager类PasswordSignInAsync方法的源:

And when sMan.PasswordSignIn(...) on the SignInManager is executed, no matter what, the SignInManager always runs functionality in the UserManager that depends on the optional interfaces. Here's the source for the PasswordSignInAsync method from the SignInManager class:

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

它总是调用UserManager.IsLockedOutAsync()它试图检查密码,如果店里没有实现IUserLockoutStore接口之前,一个异常抛出获取每一次不管是什么。

It always calls UserManager.IsLockedOutAsync() before it tries to check the password, so if the store doesn't implement the IUserLockoutStore interface, an exception gets thrown every time no matter what.

这是否意味着使用的UserManager和SignInManager类的默认功能,你需要实现我每次*商店界面?

Does this mean that to use the default functionality of the UserManager and SignInManager classes, you need to implement every I*Store interface?

它看起来的解决方法是从SignInManager继承和覆盖PasswordSignInAsync方法。是标准的做法?

It looks the the workaround is to inherit from SignInManager and override the PasswordSignInAsync method. Is that the standard practice?

谢谢!

推荐答案

我发现,身份的框架是不符合所需的I *店可选性是一致的。在如果提供所需的存储它检查一些公共方法,在其他一些地方,它只是呼吁方法。我还没有想出哪些是绝对需要的,哪些可以不叫。所以,我会去与该异常跟踪和实施的任何商店都需要为您的应用程序。

What I found that Identity framework is not consistent with "optionality" of required I*Store. In some public methods it checks if the required Store is provided, in some other places it just calls for the method. I have not figured out which ones are absolutely required and which ones can be not called. So I'd go with the exception trail and implement whatever the stores are required for your application.

这篇关于当实现自己的IUserStore,是&QUOT;可选&QUOT;在类接口实际上是可选的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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