小编ale*_*svi的帖子

如何使用.netcore 2.0身份和cookie身份验证正确设置会话超时

我正在尝试在asp.netcore 2.0 MVC应用程序中使用带有cookie身份验证的身份.我想将会话超时设置为150天,因此登录的用户不需要在很长一段时间内再次登录.我设置options.ExpireTimeSpan = TimeSpan.FromDays(150);但会话在几分钟后关闭,即使用户正在积极使用该应用程序.

我正在关注官方文档,我在Startup.cs上有这个:

ConfigureServices方法:

    services.AddIdentity<User, Role>()
            .AddDefaultTokenProviders();

    // Identity Services
    services.AddTransient<IUserStore<User>, UserService>();
    services.AddTransient<IRoleStore<Role>, RoleService>();

    services.Configure<IdentityOptions>(options =>
    {
        // Password settings
        options.Password.RequireDigit = false;
        options.Password.RequiredLength = 8;
        options.Password.RequireNonAlphanumeric = false;
        options.Password.RequireUppercase = false;
        options.Password.RequireLowercase = false;
        options.Password.RequiredUniqueChars = 3;

        // Lockout settings
        options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
        options.Lockout.MaxFailedAccessAttempts = 10;
        options.Lockout.AllowedForNewUsers = true;

        // User settings
        options.User.RequireUniqueEmail = true;
    });

    services.ConfigureApplicationCookie(options =>
    {
        // Cookie settings
        options.Cookie.HttpOnly = true;                
        options.ExpireTimeSpan = TimeSpan.FromDays(150);
        options.LoginPath = "/User/Login"; 
        options.LogoutPath …
Run Code Online (Sandbox Code Playgroud)

session-timeout asp.net-identity asp.net-core-2.0 cookie-authentication

7
推荐指数
0
解决办法
8578
查看次数