【发布时间】:2014-08-17 06:34:43
【问题描述】:
我正在构建一个单页应用程序,所以我使用了 Visual Studio 默认模板。 当它在开发时,我有 2 个数据库 Entityframework.mdf 和 Identity.mdf,因为这是默认配置所做的,但现在我需要与用户建立关系,我无法轻易联系到他们,因为他们在另一个数据库中。
在 MVC 模板中,您可以轻松地这样做:
public class ApplicationUser: IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<CustomTableItem> CustomTable{ get; set; }
//You can add more tables
}
当您使用单页应用程序时,它会以我不理解的方式配置用户管理。
UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>());
然后来自this article
此代码使用 UserStore 类的默认构造函数,该构造函数将创建 IdentityDbContext 对象的新实例,因为未提供对象。如果你想使用自己的 IdentityDbContext 派生类,就像 MVC 5 项目那样,你可以修改上面的初始化代码并传入你自己的上下文。
它说我可以修改它但它没有显示如何:(,我已经尝试过但我无法让它工作。这就是我想要做的
UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());
我错过了什么?
【问题讨论】:
标签: asp.net-mvc entity-framework asp.net-web-api single-page-application asp.net-identity