How to set asp.net Identity cookies expires time

后端 未结 4 543
Happy的楠姐
Happy的楠姐 2020-12-12 21:09

I use Asp.Net Identity to control my app\'s authorization. Now, I need to do this: if the user does not operate in 30 minutes, jump to the login page, when he login does not

4条回答
  •  余生分开走
    2020-12-12 21:42

    I had the same issue and this code worked for me (inside the Startup.cs file)..

    services.Configure(options =>
    {
        options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(3650);
    });
    

    This adds roughly 10 years to the persistent cookie.

    NB: If you wanted less of an expiry time you could use TimeSpan.FromMinutes(1); for 1 minute or TimeSpan.FromSeconds(30); for 30 seconds etc..

提交回复
热议问题