【发布时间】:2020-01-04 04:44:40
【问题描述】:
这不再适用于 ASP.Net Core 3.1 / .Net Core 3.1
https://stackoverflow.com/a/37173202/1698480
编译错误:“IdentityBuilder”不包含“AddEntityFrameworkStores”的定义,并且找不到接受“IdentityBuilder”类型的第一个参数的可访问扩展方法“AddEntityFrameworkStores”(您是否缺少 using 指令或程序集引用? ) WebSite.Site C:\WorkSource....\Startup.cs 32 活动
public class ApplicationUser : IdentityUser<Guid> { }
public class Role : IdentityRole<Guid> { }
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, Role, Guid>
{
...
}
public class Startup
{
...
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<ApplicationUser, Role>()
.AddEntityFrameworkStores<ApplicationDbContext, Guid>()
.AddDefaultTokenProviders()
.AddUserStore<UserStore<ApplicationUser, Role, ApplicationDbContext, Guid>>()
.AddRoleStore<RoleStore<Role, ApplicationDbContext, Guid>>();
}
}
如果我像这样删除 Guid 通用参数:
.AddEntityFrameworkStores<ApplicationDbContext, Guid>()
然后我得到浏览器错误:找不到这个本地主机页面没有找到网址的网页:http://localhost:50827/Account/Login?ReturnUrl=%2F
我该怎么做?谢谢
【问题讨论】:
-
感谢您的回复,不是真的,当我创建 UrlHelperExtensions 并添加找不到 AccountController 的方法时。添加了标识脚手架项目,但它仍然不存在。似乎这现在正在使用剃须刀页面?无论如何,如果我不包括在内,我会收到其他错误:
-
asp.net core 3.1 似乎发生了很多变化,我将通过这个文档:docs.microsoft.com/en-us/aspnet/core/security/authentication/… 也可能将它用于 MVC 而不是剃须刀页面github.com/TanvirArjel/AspNetCoreMvcIdentity