我使用ASP.NET核心与Identity Server和Open标识连接所描述这里。设置“记住我”选项时(默认为 14 天),我需要更改身份验证 cookie 的过期时间。我可以看到名为“.AspNetCore.Identity.Application”的 cookie 对此负责。我正在尝试像这样设置到期时间:
.AddCookie(options =>
{
options.Cookie.Expiration = TimeSpan.FromDays(1);
options.ExpireTimeSpan = TimeSpan.FromDays(1);
})
Run Code Online (Sandbox Code Playgroud)
但它会影响另一个名为“.AspNetCore.Cookies”(包含相同的令牌值)的 cookie,它具有 Session 过期时间并且似乎没有做任何事情。我发现的所有更改过期时间的方法都只修改了“.AspNetCore.Cookies”cookie,我找不到任何修改“.AspNetCore.Identity.Application”cookie 的方法。(顺便说一句,services.ConfigureApplicationCookie某种原因,我根本没有触发方法)。
谁能解释一下这两个 cookie 之间的区别,以及如何修改“.AspNetCore.Identity.Application”过期时间?
我的代码 Startup.ConfigureServices
services.AddMvc(options =>
{
// ...
})
services.AddAuthorization(options =>
{
options.AddPolicy(PolicyNames.UserPolicy, policyBuilder =>
{
// ...
});
});
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
})
.AddCookie(options =>
{
options.AccessDeniedPath = "/AccessDenied";
options.SlidingExpiration = true;
})
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "<authority>"; …Run Code Online (Sandbox Code Playgroud) authentication asp.net-identity openid-connect asp.net-core identityserver4
在课堂上,我有一个私有字段:
private string _extraSettings;
Run Code Online (Sandbox Code Playgroud)
我使用以下代码将其映射到名为 ExtraSettings 的列:
modelBuilder.Entity<MyClass>(e =>
{
e.Property<string>("ExtraSettings").HasField("_extraSettings").UsePropertyAccessMode(PropertyAccessMode.Field);
});
Run Code Online (Sandbox Code Playgroud)
这在 EF Core 2.2 中工作正常,但在 EF Core 3.1 中停止工作,并出现以下错误:
The specified field '_extraSettings' cannot be used for the property 'MyClass.ExtraSettings' because it does not match the property name
Run Code Online (Sandbox Code Playgroud)
MyClass 类没有 ExtraSettings 属性,但由于某种原因,它在 2.2 中有效 - 为什么它在 3.1 中不起作用,我需要做什么才能消除此错误?
asp.net-core ×1