Ste*_*nch 12 asp.net-mvc asp.net-mvc-5 asp.net-identity
股票asp.net mvc 5应用程序创建应用程序用户,即在单独的上下文中的身份用户,命名为名为"IdentityModels.cs"的文件 - 它看起来像这样
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
}
Run Code Online (Sandbox Code Playgroud)
我试图将Application用户放在常规数据上下文中,即类似这样的东西
public class BlogProphetContext : DbContext
{
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<Answer> Answers { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Tag> Tags { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是,每次我这样做时,每次尝试创建帐户时都会出现以下错误
The UserId field is required
Run Code Online (Sandbox Code Playgroud)
在AccountController.cs中,当我尝试执行以下代码行时
result = await UserManager.AddLoginAsync(user.Id, info.Login);
Run Code Online (Sandbox Code Playgroud)
我觉得我的方法是错误的,并且我没有在没有某种外部诡计的主数据上下文文件中使用ApplicationUsers - 有没有人知道这样做的某种方法?所有文件都是最新的.
Ste*_*nch 11
这有点太容易了 - 事实证明,所有你必须做的就是删除
<ApplicationUser>
Run Code Online (Sandbox Code Playgroud)
当你调用上下文时,一切都如你所料(即MVC假设和开发人员假设(在本例中为我的)同步).
这是正常工作
public class MyContext : IdentityDbContext
{
public MyContext()
: base("DefaultConnection")
{
}
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<Answer> Answers { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10039 次 |
最近记录: |