【问题标题】:add multiple cookie schemes in aspnet core 2在 aspnet core 2 中添加多个 cookie 方案
【发布时间】:2017-08-22 05:45:01
【问题描述】:

如何在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;
});

【问题讨论】:

    标签: c# asp.net cookies asp.net-core asp.net-core-mvc-2.0


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-29
      • 2018-06-05
      • 2020-03-27
      • 2017-05-11
      相关资源
      最近更新 更多