【问题标题】:how to use builtin Identity function use如何使用内置身份功能使用
【发布时间】:2019-01-24 13:57:38
【问题描述】:

我想使用内置的身份类和方法来创建用户并从中获取令牌进行身份验证我花了 7 8 个小时在这但不成功不知道如何使用它 我首先使用实体​​框架代码如何创建使用..从电子邮件和密码验证用户请任何人帮助我,非常感谢 .net 核心 2.1 和 2.2

  private UserManager<ApplicationUser> _userManager = null;
        private readonly SignInManager<ApplicationUser> _signInManager;


async Task<bool> CreateIdentityUserAsync(string email, int userid, string password)
        {
            var user = new ApplicationUser
            {
                UserName = "abc@gmail.com",
                Email = "abc@gmail.com",
                OrgaId = 1,
                RegisteredUserId = 1,
            };
            var result = await _userManager.CreateAsync(user, "s@r@hi123);

            return result.Succeeded;
        }][1]][1]

public class ApplicationUser : IdentityUser
    {

    }

列名“NormalizedUserName”无效。 列名“ConcurrencyStamp”无效。 列名“LockoutEnd”无效。

【问题讨论】:

  • ApplicationUser 的定义是什么?是继承自IdentityUser吗?
  • 是的......我编辑我的问题添加应用程序用户类
  • 好像没问题,有没有演示或详细步骤可以重现您的问题?

标签: c# .net-core asp.net-identity asp.net-core-webapi


【解决方案1】:

改变你的行:

private UserManager<ApplicationUser> _userManager = null;
private readonly SignInManager<ApplicationUser> _signInManager;

private readonly UserManager<IdentityUser> _userManager;
private readonly SignInManager<IdentityUser> _signInManager;

你还需要为它们做依赖注入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 2018-07-22
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    相关资源
    最近更新 更多