1

如何添加多个 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;
});
4

1 回答 1

6

添加多个方案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 迁移公告

于 2017-08-22T06:32:54.070 回答