locked
identity and session timeout RRS feed

  • Question

  • User-819032351 posted

    I use Identity core 3.1 . How can I complete a user's session after 20 minutes?

    Thursday, July 9, 2020 7:27 AM

Answers

  • User-2054057000 posted

    Use this code in the ConfigureServices() method of Startup class:

    services.ConfigureApplicationCookie(options =>
    {
    options.Cookie.Name = ".AspNetCore.Identity.Application";
    options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
    options.SlidingExpiration = true;
    });

    Identity cookie name is .AspNetCore.Identity.Application which you can check it in the developer tools of the browser (see below image).

    More info see - Identity Cookie Timeout

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 9, 2020 9:33 AM
  • User711641945 posted

    Hi MLT111,

    If you want to set expiration of identity cookie,set like below:

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

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 9, 2020 9:46 AM

All replies

  • User-2054057000 posted

    Use this code in the ConfigureServices() method of Startup class:

    services.ConfigureApplicationCookie(options =>
    {
    options.Cookie.Name = ".AspNetCore.Identity.Application";
    options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
    options.SlidingExpiration = true;
    });

    Identity cookie name is .AspNetCore.Identity.Application which you can check it in the developer tools of the browser (see below image).

    More info see - Identity Cookie Timeout

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 9, 2020 9:33 AM
  • User711641945 posted

    Hi MLT111,

    If you want to set expiration of identity cookie,set like below:

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

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 9, 2020 9:46 AM
  • User-819032351 posted

    Is it possible to automatically redirect to the login page when 20 minutes have elapsed?

    Thursday, July 9, 2020 3:38 PM
  • User711641945 posted

    Hi MLT111,

    Is it possible to automatically redirect to the login page when 20 minutes have elapsed?

    Be sure you have added the following code,then it would automatically redirect to the login page:

    services.ConfigureApplicationCookie(options =>
     {
         //other options...
         options.LoginPath = "/Account/Login";
    options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
    });

    Best Regards,

    Rena

    Friday, July 10, 2020 1:18 AM
  • User-2054057000 posted

    Is it possible to automatically redirect to the login page when 20 minutes have elapsed?

    You will need to reload your page every 20 minutes time from JavaScript. So if the user's timeout is already done then due to the page reload he will be redirected to the login page. 

    You can simply use the setInterval method of JavaScript to do the page reload every 20 minutes time.

    setInterval(function(){ 
        location.reload(); 
    }, 1000*60*20);

    There are also some chrome extensions to do the automatic page reload after a given time. See https://chrome.google.com/webstore/detail/super-auto-refresh-plus/globgafddkdlnalejlkcpaefakkhkdoa?hl=en

    Friday, July 10, 2020 5:40 AM