当前,这有效,我正在使用IDENTITY在ASP MVC Core 2应用程序中设置Cookie Authentication:
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,并且根据此处的文档,我通过使用类似的内容来做到这一点(基于与上述相同的配置):
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
只是对同一事物的快捷方式。
我错过了什么吗?
谢谢Brian
尝试以下内容:
services.AddAuthentication()
.AddJwtBearer(options =>
{
// Jwt options.
});
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
});