Rob*_*bin 1 c# asp.net cookies asp.net-core asp.net-core-mvc-2.0
如何在 中添加多个 cookie 方案aspnet core 2.0
?
我已按照此处的Auth 2.0 迁移公告 和此处的将身份验证和身份迁移到 ASP.NET Core 2.0 中的说明进行操作, 但我无法添加多个方案。
例如:
services.AddAuthentication("myscheme1").AddCookie(o =>{
o.ExpireTimeSpan = TimeSpan.FromHours(1);
o.LoginPath = new PathString("/forUser");
o.Cookie.Name = "token1";
o.SlidingExpiration = true;
});
services.AddAuthentication("myscheme2").AddCookie(o =>{
o.ExpireTimeSpan = TimeSpan.FromHours(1);
o.LoginPath = new PathString("/forAdmin");
o.Cookie.Name = "token2";
o.SlidingExpiration = true;
});
Run Code Online (Sandbox Code Playgroud)
添加多个方案aspnet core 2.0
很简单。我已经通过这样做解决了。
services.AddAuthentication()
.AddCookie("myscheme1", o => // scheme1
{
o.ExpireTimeSpan = TimeSpan.FromHours(1);
o.LoginPath = new PathString("/forUser");
o.Cookie.Name = "token1";
o.SlidingExpiration = true;
})
.AddCookie("myscheme2", o => //scheme2
{
o.ExpireTimeSpan = TimeSpan.FromHours(1);
o.LoginPath = new PathString("/forAdmin");
o.Cookie.Name = "token2";
o.SlidingExpiration = true;
});
Run Code Online (Sandbox Code Playgroud)
可以在这里找到讨论Auth 2.0 Migration 公告
归档时间: |
|
查看次数: |
2254 次 |
最近记录: |