【问题标题】:UserManager.FindAsync to use custom Userstore's FindByIdAsync method instead of FindByNameAsyncUserManager.FindAsync 使用自定义 Userstore 的 FindByIdAsync 方法而不是 FindByNameAsync
【发布时间】:2016-08-09 23:58:46
【问题描述】:

我正在使用身份框架。 当我登录到我的应用程序时,appUser 检索 UserManager 如下:

Patient patient = await UserManager.FindAsync(model.Id, model.Password);

据我调试了解,UserManager.FindAsync 使用来自 UserStore 的 FindByNameAsync(string userName)(我有一个自定义 UserStore)。

问题是:如何告诉 UserManager.FindAsync 使用我的自定义 UserStore 的 FindByIdAsync 方法而不是 FindByNameAsync?

我还需要编写自定义 UserManager 吗?

提前致谢。

【问题讨论】:

    标签: asp.net-identity usermanager


    【解决方案1】:

    您可以在自定义 UserManager 中覆盖该方法

    public class ApplicationUserManager : UserManager<AppUser, string>
    {
         public override async Task<AppUser> FindAsync(string id, string password)
         {
             var user = await FindByIdAsync(id).WithCurrentCulture();
             if (user == null)
             {
                 return null;
             }
             return await CheckPasswordAsync(user, password).WithCurrentCulture() ? user : null;
         }   
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-29
      • 2016-11-18
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 2023-03-21
      • 2016-02-06
      • 1970-01-01
      相关资源
      最近更新 更多