我正在尝试使用.Net core 2.0角度模板实现身份验证(在Visual Studio 2017中)。我尝试使用asp.net Identity尝试关注this tutorial
我马上就把dbContext添加到startUp.cs。
StartUp.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<EduSmartContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc();
}
我在startup.cs中添加applicationDbContext:
时出现此错误类型&#39; EduSmart.Data.ApplicationDbContext&#39;不能用作类型 参数&#39; TContext&#39;在泛型类型或方法中 &#39; EntityFrameworkServiceCollectionExtensions.AddDbContext(IServiceCollection, Action,ServiceLifetime,ServiceLifetime)&#39;。 没有隐式引用转换 &#39; EduSmart.Data.ApplicationDbContext&#39;至 &#39; Microsoft.EntityFrameworkCore.DbContext&#39 ;. EduSmart C:\ src \ EduSmart \ Startup.cs 30活动
我正在寻找以下三个选项之一:
答案 0 :(得分:1)
没有看到更多代码,我想
1.解决上面的错误。
因为它表明你的ApplicationDbContext
不是从DbContext派生的。我认为将EduSmartContext
实体移至ApplicationDbContext
将为您完成工作。
public class EduSmartContext : IdentityDbContext<ApplicationUser>
{
public EduSmartContext(DbContextOptions<EduSmartContext> options)
: base(options)
{
}
public DbSet<Poco1> Poco1s { get; set; }
...
...
2.指向更清晰的分步教程的链接,以使用asp.net Identity实现身份验证
最好使用Asp.net核心webapi搜索基于令牌的身份验证。 https://logcorner.com/token-based-authentication-using-asp-net-web-api-core/
3.建议使用链接资源验证Angular Asp.Net核心应用程序的更好方法
如果您愿意为此投资,我建议您使用身份验证服务器,也称为STS(安全令牌服务器) 例如IdentityServer4或OpenIdDict 如果是IdentityServer,这篇文章可能会有所帮助: