Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am working on .Net Core 6(MVC) web application, i set the idle timeout for 2 minutes, when i am moving from one page to another page then the session is working correctly, but when i am staying on any particular page and i am moving the cursor on page or filling the form then the session getting expired in 2 minutes, please see the below code what i am doing wrong and how to fix it.


Thanks

What I have tried:

program.cs code:
builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(2);
    options.Cookie.HttpOnly = true;
    options.Cookie.IsEssential = true;
   
});


Login code:
await _signInManager.SignInAsync(
user,
new AuthenticationProperties
{
    ExpiresUtc = DateTime.UtcNow.AddMinutes(2),
    AllowRefresh = true,
    IsPersistent = true
});
Posted

Quote:
i set the idle timeout for 2 minutes, ... then the session getting expired in 2 minutes

It's doing exactly what you told it to do! You said expire the session in 2 minutes, so the session is expiring in 2 minutes. What did you think was going on?

From your own code:
C#
builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(2);        <---- Here's your 2 minute timeout.
    options.Cookie.HttpOnly = true;
    options.Cookie.IsEssential = true;
   
});

If the user doesn't request a new page inside of 2 minutes, the session times out.
 
Share this answer
 
v2
Comments
sysproteam123@gmail.com 16-Apr-24 11:53am    
Thanks Dave
To add to what Dave has said, the session is a Server side construct, not Client - so it's expiration is unrelated to user input unless that input directly causes the Client browser to send (or request) information from the server.
Just moving about a form or filling in details in form controls does not do that, it is entirely local to the Client computer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900