【问题标题】:How to add asp.net identity to existing web api project?如何将 asp.net 身份添加到现有的 web api 项目?
【发布时间】:2015-11-04 12:48:21
【问题描述】:

我的解决方案中有 2 个项目。第一个是简单的 mvc 项目,另一个是 web api。 web api 中没有预先编写的代码。我自己把所有的逻辑。现在我想在 web api 项目中添加 asp.net 身份。我怎样才能做到这一点? 谢谢。

【问题讨论】:

标签: asp.net-mvc-4 asp.net-identity asp.net-identity-2


【解决方案1】:

在您的 web api 项目中,您可以这样做: 1. 创建一个如下所示的 DbContext 类:

public class DataContext : IdentityDbContext<IdentityUser>
{
    public DataContext() : base("ConnectionStringLocal") { }
}
  1. 在您的 Web.config 文件中添加连接字符串

  2. 在包管理器控制台中,执行Enable-MigrationsAdd-Migration IdentityUpdateUpdate-Database。这将创建一个内置 asp.net 身份的数据库。

如果您还有其他问题,请告诉我。

【讨论】:

  • 谢谢你,我在网上搜索为什么 add-migration 命令没有生成任何内置的 aspnet 身份表。我忘了继承IdentityDbContext
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 2012-08-12
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
相关资源
最近更新 更多