当用户在ASP.NET核心标识中处于非活动状态时禁用自动注销

2uluyalo  于 2023-02-17  发布在  .NET
关注(0)|答案(1)|浏览(130)

我尝试将此代码解析为IdentityHostingStartup.cs:

services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Name = ".AspNetCore.Identity.Application";
                options.ExpireTimeSpan = TimeSpan.FromDays(1);
                options.SlidingExpiration = true;
                options.LoginPath = "/Identity/Account/Login";
            });

但它不工作。用户得到注销后10-20分钟,如果他是不活动的。重定向到登录页面不工作太。Startup.cs不使用服务,所以我不能实现这个代码在这个类上。我也检查了cookie的生存时间和时间是正确的。但我不明白如何解决这个问题,最大限度地延长时间从注销和设置重定向到登录页面... see this pic
希望你能帮助我,谢谢.我所有的IdentityHostingStartup代码:

public class IdentityHostingStartup : IHostingStartup
{
    public void Configure(IWebHostBuilder builder)
    {
        builder.ConfigureServices((context, services) => {
            services.AddDbContext<PerceptionDbContext>(options =>
                options.UseSqlServer(
                    context.Configuration.GetConnectionString("PerceptionContextConnection")));

            services.AddDefaultIdentity<PerceptionUser>(options =>
            {
                options.SignIn.RequireConfirmedEmail = true;
                options.SignIn.RequireConfirmedAccount = false;
                options.Password.RequireLowercase = false;
                options.Password.RequireUppercase = false;
                options.Password.RequireNonAlphanumeric = false;
            })
            .AddRoles<IdentityRole>()
            .AddEntityFrameworkStores<PerceptionDbContext>();
            
            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Name = ".AspNetCore.Identity.Application";
                options.ExpireTimeSpan = TimeSpan.FromDays(1);
                options.SlidingExpiration = true;
                options.LoginPath = "/Identity/Account/Login";
            });
        });
    }
}
jutyujz0

jutyujz01#

我也遇到了同样的问题,花了很长时间试图弄清楚到底是怎么回事。最后我发现了这个问题:https://github.com/dotnet/aspnetcore/issues/12166
在我的Startup.cs中添加下面的行似乎已经为我修复了它:

services.Configure<SecurityStampValidatorOptions>(o => o.ValidationInterval = TimeSpan.FromHours(10));

相关问题