【问题标题】:Dot Net Core 2.0 multiple cookiesDot Net Core 2.0 多个 cookie
【发布时间】:2018-08-09 13:52:44
【问题描述】:

我正在尝试将网站迁移到核心 2.0。有多个 cookie,形式为,

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "cookieA",
    AutomaticAuthenticate = false,
    AutomaticChallenge = false
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "cookieB",
    AutomaticAuthenticate = false,
    AutomaticChallenge = false
});

这些 cookie 用于跟踪用户在登录过程中的位置。我看到在核心 2.0 中,这个过程发生了变化,并移至服务管道,但我不清楚如何创建多个 cookie,以及如何翻译这些设置。此外,我正在使用身份服务器 4,并且需要不修改其所有必需的 cookie。这在以前的版本中不是问题,但看起来可能是这里的问题。

谢谢。

【问题讨论】:

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


    【解决方案1】:

    您需要为您的服务添加多个 cookie 身份验证

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddAuthentication()
                .AddCookie("CookieA", optionA =>
                {
                    // config cookieA
                })
                .AddCookie("CookieB", optionB =>
                {
                    // config cookieB
                });
        }
    }
    

    【讨论】:

    • 是的,我想知道如何为每个 cookie 转换 AutomaticAuthenticate 和 Automatic Challenge 标志。除了一个 cookie 之外,所有 cookie 都将这些设置为 false,但有一个设置为 true。
    猜你喜欢
    • 1970-01-01
    • 2017-11-28
    • 2018-08-01
    • 1970-01-01
    • 2021-10-21
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多