c# - UserManager<User> 在数据库中找不到现有用户 asp.net core Identity

标签 c# asp.net asp.net-core-2.1 asp.net-core-identity

我有 ASP.NET Core 2.1 MVC 应用程序。同样在数据库中,我有 1 个用户角色“Admin”,但是当我尝试获取数据库中的用户列表时,它返回一个空列表。它通常从“Roles”和“UserRoles”表返回数据,但看不到任何“用户”表中的数据,因此我无法使用 SignInAsync 或 PasswordSignInAsync 方法。 这是我的 dbContext:

public class AppDbContext : IdentityDbContext<User, Role, string>
{
    public AppDbContext(DbContextOptions<AppDbContext> options):base(options)
    { }

    // ...
}

这是我的创业公司:

services.AddDbContext<AppDbContext>(options =>
{
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
});

services.AddIdentity<User, Role>()
    .AddEntityFrameworkStores<AppDbContext>()
    .AddDefaultTokenProviders();

// ...

最佳答案

确保 NORMALIZEDUSERNAME 和 NORMALIZEDEMAIL 在电子邮件和大写用户名上具有相同的值。

关于c# - UserManager<User> 在数据库中找不到现有用户 asp.net core Identity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52762164/

相关文章:

javascript - Asp.Net Core 2.1 请求排除客户端 cookie

c# - 在 Startup.cs 的 Configure 中获取域名或主机名和端口

asp.net - 在自托管 Web 应用程序中使用性能计数器

c# - 如何在 EF Core 2.1.0 中设置管理员用户?

c# - ASP.NET 和 MVC.NET 解决方案之间的单点登录选项?

c# - 从根开始构建 Assimp 骨骼层次结构

c# - 错误信息 "Operator ' .' cannot be applied to operand of type ' lambda expression '"when converting a method to Extension Method?

C#异常处理,使用哪个catch子句?

c# - MVC 4 绑定(bind)到子表列表

javascript - 将数据加载到 HTML 中的可变高度表