c# - 自定义 ASP.NET Identity 2.0 UserStore - 是否需要实现所有接口(interface)?

标签 c# asp.net asp.net-identity-2

我创建了一个自定义 IUserStore<TUser,int>为我的申请。我已经实现了我需要的接口(interface),

   IUserStore<TUser, int>,
   IUserRoleStore<TUser, int>,
   IUserLockoutStore<TUser, int>,
   IUserPasswordStore<TUser, int>

但是当我打电话的时候

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

我得到一个异常(exception)说

Store does not implement IUserTwoFactorStore<TUser>.

我没有在我的应用程序中的任何地方使用双因素身份验证。为什么它希望我实现该接口(interface)?是否需要我实现所有这些接口(interface),即使我实际上并不使用它们?

最佳答案

实际上 IUserTwoFactorStore 接口(interface)非常简单,到目前为止我的实现(我也不使用双因素身份验证)是这样的:

 ....
 public Task<bool> GetTwoFactorEnabledAsync(User user)
 {
     return Task.FromResult(false);
 }

 public Task SetTwoFactorEnabledAsync(User user, bool enabled)
 {
     throw new NotImplementedException();
 }

虽然我几分钟前刚刚做过,但没有彻底测试整个应用程序,但它确实有效。

关于c# - 自定义 ASP.NET Identity 2.0 UserStore - 是否需要实现所有接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25551295/

相关文章:

c# - ISO/IEC 8859-2 字符的正则表达式

c# - 需要获取我创建的 dll 类库的当前路径

asp.net-mvc - 如何为不同的用途设置不同的 UserTokenProvider 生命周期。身份 2.0

asp.net-web-api - 除了 OAuth OWIN/Web Api 之外的 API key

c# - 没有换行符的文本文件中是否有最大行长?

c# - 如何在 ASP.Net 页面上将 List<string> 的 URL 显示为超链接(C#)

c# - 如何将动态值传递给EventHub属性Azure函数c#

asp.net - 如何在网站项目中创建嵌入式资源?

c# - Visual Studio 2013 "break on handled exceptions"不工作,不中断

asp.net-mvc-5 - 在单独的项目中使用身份用户模型的 Entity Framework 6 代码优先迁移