Different Session Time out .net core Session

妖精的绣舞 提交于 2019-12-13 03:47:20

问题


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.

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

-Thanks for your help


回答1:


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

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

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
    });
}


来源:https://stackoverflow.com/questions/52483098/different-session-time-out-net-core-session

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!