在ASP.NET Core 2.1中,确实没有AddSignIn方法。然而,您可以通过以下两种方法解决此问题:
services.AddAuthentication()
.AddCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
});
这将添加Cookie身份验证服务,并设置登录和注销路径。
services.AddIdentity()
.AddDefaultUI()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
});
这将添加Identity身份验证服务和IdentityUser和IdentityRole类,以及用于存储用户和角色的数据库上下文。
请注意,上述示例假定您使用Entity Framework Core作为数据存储。如果您使用其他存储方式,请相应地更改AddEntityFrameworkStores方法的参数。
希望这可以帮助到您!
上一篇:ASP.Net Core 2.1 中间件 WindowsPrincipal ClaimsPrincipal
下一篇:ASP.Net Core 2.1/WebAPI应用程序:调用带有[Authorize]的REST URL时出现“HTTP 404未找到”