不同的会话超时.net核心会话 [英] Different Session Time out .net core Session

查看:59
本文介绍了不同的会话超时.net核心会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 .net core 2 构建 API我想更改不同用户的会话超时.这就像是每个人的默认会话超时(24 小时)(我可以从服务配置中做到这一点).如果有人说让我保持登录状态",那么会话超时将是一个月或更长时间.

I am building an API using .net core 2 I want to change the session time out for different users. It will be like the is a default session time out(24 Hour) for every one (which I can do from service configuration). And if some one says 'keep me logged in' then the session time out will be a month or larger.

但是 .net core 不像以前的 .net 版本那样有 Session.Current Session我可以在其中更改会话超时值.

But .net core does not have Session.Current Session like the previous .net versions where I can change the session Time Out value.

-感谢您的帮助

推荐答案

对于默认 cookie 过期,您可以在 Startup.cs 中设置:

For default cookie expiration you could setup in Startup.cs:

services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromHours(24);
});

对于那些想要保持登录状态的人,您可以在登录时更改 cookie 到期日期:

And for those who wants to stay logged in you could change cookie expiration date upon login:

var result = await this.signInManager.CheckPasswordSignInAsync(account, password, false);
if (result.Succeeded)
{
    await this.signInManager.SignInAsync(account, new AuthenticationProperties
    {
        ExpiresUtc = DateTime.UtcNow.AddDays(30),
        IsPersistent = true
    });
}

这篇关于不同的会话超时.net核心会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆