扩展核心2.1身份验证Cookie的过期时间

时间:2018-10-23 13:54:07

标签: asp.net-mvc .net-core asp.net-identity

您好,我试图在mvc核心2.1身份中花费身份验证Cookie的过期时间 我有以下代码:到服务启动,然后重定向到Url,而不是重定向到“ localhost:44339 / Identity / Account / Login?ReturnUrl =%FBLABLA 正在重定向到“ localhost:44339 / Account / Login?ReturnUrl =%2FBLABLA (缺少“ / Identity /”),因此它的错误为404。 我添加的代码是: services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(option => { option.Cookie.Expiration = TimeSpan.FromHours(5); });

& the complete StartUp:




public void ConfigureServices(IServiceCollection services)
                {
                    services.Configure<CookiePolicyOptions>(options =>
                    {
                        // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                        options.CheckConsentNeeded = context => true;
                        options.MinimumSameSitePolicy = SameSiteMode.None;
                    });

                    services.AddDbContext<ApplicationDbContext>(options =>
                        options.UseSqlServer(
                            Configuration.GetConnectionString("DefaultConnection")));
                    services.AddDefaultIdentity<IdentityUser>()
                        .AddEntityFrameworkStores<ApplicationDbContext>();
                    //ToDo Check If this doesn't couse Error
                    services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                      .AddCookie(option => { option.Cookie.Expiration = TimeSpan.FromHours(5); });

                    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                }

0 个答案:

没有答案