首页 > 解决方案 > 跨会话保留 ASP.NET Core 3.1 身份外部登录身份验证 cookie

问题描述

我在我的 .NET Core 3.1 项目中使用 ASP.NET Core Identity,并且很难弄清楚如何跨会话保留从外部登录提供程序(例如 Microsoft 或 Google)创建的 cookie。到目前为止,cookie 始终是会话 cookie,无论我尝试过哪个扩展点,都没有改变它。

检查source,可以假设以下方法应该有效,但事实并非如此:

services.AddAuthentication()
    .AddMicrosoftAccount(options =>
    {
        ...

        options.Events.OnTicketReceived = ctx =>
        {
            ctx.Properties.IsPersistent = true;
            ctx.Properties.ExpiresUtc = DateTime.Now.AddDays(7);

            return Task.CompletedTask;
        };
    });

事件处理程序被成功调用,但.AspNetCore.Identity.Applicationcookie 保持不变。我很确定我在这里遗漏了一些相当重要的东西——也就是在错误的地方挖掘:)

标签: c#asp.netcookiesasp.net-identity

解决方案


推荐阅读