【发布时间】:2019-03-22 09:23:49
【问题描述】:
我在 -net Core 2 api 中实现身份验证,我在这段代码之后发现了这个错误:
StartUp.cs:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<MyContext>()
.AddDefaultTokenProviders();
MyContext.cs:
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
public class MyContext: IdentityDbContext<IdentityUser>
{
public MyContext(DbContextOptions<MyContext> opt)
: base(opt) { }
public DbSet<Room> Rooms{ get; set; }
}
MyCONtext.cs 中的错误:
'IdentityUser' is an ambiguous reference between 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUser' and 'Microsoft.AspNetCore.Identity.IdentityUser'
谢谢大家。
【问题讨论】:
-
使用 Microsoft.AspNetCore.Identity 删除;在 MyContext.cs 中
标签: c# entity-framework .net-core