我有以下代码:
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = System.TimeSpan.FromMinutes(1),
LoginPath = new PathString("/Account/Login"),
LogoutPath = new PathString("/Account/LogOff")
});
Run Code Online (Sandbox Code Playgroud)
但登录会话活动超过1分钟.此外,时间到期时不会调用LogoutPath.为什么?
我有带有 Angular 的 IdentityServer4。令牌每 5 分钟静默刷新一次。但是 30 分钟后,用户将自动注销。我试图以某种方式设置终身 cookie,但没有成功。
这是我目前的配置:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Identity")));
services.AddIdentity<AppUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 6;
options.Password.RequireLowercase = false;
options.Password.RequireUppercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireDigit = false;
options.SignIn.RequireConfirmedEmail = true;
options.User.RequireUniqueEmail = true;
options.User.AllowedUserNameCharacters = null;
})
.AddEntityFrameworkStores<AppIdentityDbContext>()
.AddDefaultTokenProviders();
services.AddIdentityServer(options => options.Authentication.CookieLifetime = TimeSpan.FromHours(10))
.AddDeveloperSigningCredential()
.AddInMemoryPersistedGrants()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients(Configuration["AppUrls:ClientUrl"]))
.AddAspNetIdentity<AppUser>();
services.AddTransient<IProfileService, IdentityClaimsProfileService>();
services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()));
services.AddRazorPages().AddRazorRuntimeCompilation();
}
Run Code Online (Sandbox Code Playgroud)
@编辑
如果我会添加
services.Configure<SecurityStampValidatorOptions>(options =>
{
options.ValidationInterval = TimeSpan.FromHours(24); …Run Code Online (Sandbox Code Playgroud)