首页 > 解决方案 > asp.net core cookie 身份验证滑动过期不起作用

问题描述

我在asp.net core 2应用中配置了cookie认证,这里是startup,cs文件中的配置

 //1:
        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
        options =>
        {
            //REF:https://tahirnaushad.com/2017/09/08/asp-net-core-2-0-cookie-authentication/
            //Cookie Authentication Options

            //Login View
            options.LoginPath = "/Account/Login";
            //Logout Action
            options.LogoutPath = "/Account/Logout";
            //Controls how much time the cookie will remain valid from the point it is created. 
            options.SlidingExpiration = true;
            //Ticket Expiration :represents the expiration of the ticket NOT the cookie that contains the ticket.
            //an expired cookie will be ignored even if it is passed to the server after the browser should have purged it.
            options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
            //Cookie Expiration
            options.Cookie.Expiration = TimeSpan.FromMinutes(10);
            //override default name of cookie, which is .AspNetCore.Cookies
            options.Cookie.Name = "HDAPP1.0";
            //cookie can be accessed from client side scripts
            options.Cookie.HttpOnly = false;


            //ReturnUrlParameter = "returnUrl"
        });

        //2:
        services.AddAuthentication(options =>
        {
            options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        });

        //3:add app.UseAuthentication(); in Configure Method

问题是滑动到期不起作用,应用程序总是在 10 分钟内注销,无论您是否在网站上进行工作。

标签: authenticationcookies

解决方案


推荐阅读