asp.net-identity - Asp Mvc Core 2 Identity 在使用 AddAuthentication().AddCookie() 时未设置 cookie 名称

标签 asp.net-identity asp.net-core-2.0

目前,这有效,我正在执行以下操作,使用 Identity 在 ASP MVC Core 2 应用程序中设置 cookie 身份验证:

services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromDays(1);
    options.SlidingExpiration = true;
    options.LoginPath = "/Account/LogIn";
    options.LogoutPath = "/Account/LogOff";
    options.Cookie.Name = "MyCookieName";
    options.AccessDeniedPath = "/Account/AccessDenied";
});

我想将 JWT 添加到此应用程序并根据文档 here ,我通过使用类似的东西来做到这一点(基于与上面相同的配置):

services.AddAuthentication()
.AddCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromDays(1);
    options.SlidingExpiration = true;
    options.LoginPath = "/Account/LogIn";
    options.LogoutPath = "/Account/LogOff";
    options.Cookie.Name = "MyCookieName";
    options.AccessDeniedPath = "/Account/AccessDenied";
})
.AddJwtBearer(options =>
{ // options });

当我这样做时(即使我离开 AddJwtBearer 链),cookie 不再被赋予我指定的名称。登录过程仍然有效,我得到一个 cookie,但它被命名为默认的 Asp cookie 名称。

我假设这两种设置选项的方法是相同的,并且 ConfigureApplicationCookie 只是同一事物的快捷方法。

我错过了什么吗?

谢谢, 布赖恩

最佳答案

尝试以下操作:

services.AddAuthentication()
        .AddJwtBearer(options =>
        {
            // Jwt options.
        });

services.ConfigureApplicationCookie(options =>
{
    // Cookie settings
});

关于asp.net-identity - Asp Mvc Core 2 Identity 在使用 AddAuthentication().AddCookie() 时未设置 cookie 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47913510/

相关文章:

c# - 测试派生类时如何模拟基本方法

c# - 使用单独的类获取asp.net core identity中的所有角色

c# - ASP.NET 核心 2 : Ajax calls to API with [Authorize] fail the preflight request

asp.net-identity - Thinktecture.IdentityServer.v3 中的 asp.net 身份角色声明

c# - 列出 C# 中 System.Security.Claims.ClaimTypes 中存储的所有声明类型

c# - 动态添加角色以授权 Controller 的属性

.net - 将 WCF 绑定(bind)从 ASP.NET 迁移到 ASP.NET Core 完整框架

c# - Asp.Net Core 2 中是否有相当于 "HttpContext.Response.Write"的值?

dependency-injection - Asp.net core 2.0 AutoMapper IValueResolver 依赖注入(inject)

c# - T4 模板无法加载文件或程序集 'System.Runtime, Version = 4.2.0.0'