在 aspnet core 2 中添加多个 cookie 方案
add multiple cookie schemes in aspnet core 2
如何在 aspnet core 2.0
中添加多个 cookie 方案?
我已按照此处的说明进行操作 Auth 2.0 Migration announcement
在这里 Migrating Authentication and Identity to 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;
});
在 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;
});
可以在这里找到讨论Auth 2.0 Migration announcement
如何在 aspnet core 2.0
中添加多个 cookie 方案?
我已按照此处的说明进行操作 Auth 2.0 Migration announcement 在这里 Migrating Authentication and Identity to 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;
});
在 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;
});
可以在这里找到讨论Auth 2.0 Migration announcement