身份不工作,无法访问身份数据
Identity not working and cannot access Identity data
我不确定我做了什么,但我似乎搞砸了我的 ASP.NET 核心身份。它正在工作。我能够创建一个帐户并登录。但是现在我无法登录,忘记密码功能也不会给我发送电子邮件。一些测试表明 UserManager.FindByNameAsync()
在有数据匹配请求时返回 null
。
我在调试时得到了一些奇怪的结果。以下行 returns 我数据库中的所有 Goal
。
var goals = DbContext.Goals.AsEnumerable();
但是,下一行 returns 是一个空的结果集。 (我在 AspNetUsers table 中有一行。)
var users = DbContext.Users.AsEnumerable();
我没有在这个项目中搭建 Identity。这里有一些相关的 classes.
ApplicationUser.cs
public class ApplicationUser : IdentityUser
{
// Space to add custom fields
}
ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext
{
public DbSet<Area> Areas { get; set; }
public DbSet<Goal> Goals { get; set; }
public DbSet<Task> Tasks { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
所以基本上任何试图访问身份 classes 的东西都会失败。什么可能会阻止我阅读用户 table?我唯一能想到的就是我把 ApplicationUser
class 搞砸了。任何人都可以推荐我还可以尝试隔离这个吗?我被屏蔽了。
此外,如果您想使用自定义用户数据,您还需要使用 ApplicationUser
类型作为上下文的通用参数:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
我不确定我做了什么,但我似乎搞砸了我的 ASP.NET 核心身份。它正在工作。我能够创建一个帐户并登录。但是现在我无法登录,忘记密码功能也不会给我发送电子邮件。一些测试表明 UserManager.FindByNameAsync()
在有数据匹配请求时返回 null
。
我在调试时得到了一些奇怪的结果。以下行 returns 我数据库中的所有 Goal
。
var goals = DbContext.Goals.AsEnumerable();
但是,下一行 returns 是一个空的结果集。 (我在 AspNetUsers table 中有一行。)
var users = DbContext.Users.AsEnumerable();
我没有在这个项目中搭建 Identity。这里有一些相关的 classes.
ApplicationUser.cs
public class ApplicationUser : IdentityUser
{
// Space to add custom fields
}
ApplicationDbContext.cs
public class ApplicationDbContext : IdentityDbContext
{
public DbSet<Area> Areas { get; set; }
public DbSet<Goal> Goals { get; set; }
public DbSet<Task> Tasks { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
所以基本上任何试图访问身份 classes 的东西都会失败。什么可能会阻止我阅读用户 table?我唯一能想到的就是我把 ApplicationUser
class 搞砸了。任何人都可以推荐我还可以尝试隔离这个吗?我被屏蔽了。
此外,如果您想使用自定义用户数据,您还需要使用 ApplicationUser
类型作为上下文的通用参数:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>