question

antnationlab-6632 avatar image
0 Votes"
antnationlab-6632 asked antnationlab-6632 edited

Refresh views when Cookies' Ticket is about to expire

I'm using .NET 5 and OpenID Connect, with cookie configured with SlidingExpiration = true and ExpireTimeSpan = 20 minutes.

What I observe is that while I am working on task in the application and not knowing the cookie's ticket has expire due to the ExpireTimeSpan. The application will not execute any function example: prompting me that time is about the expire or log me out.

What I understand so far is that SlidingExpiration should provide me with a new ticket if they refresh the page 10 mints or so, but what I notice it is otherwise.

So I wonder is there anyway I can get the cookie's ticket renew before the expire and the task/process should be transparent to me. What I notice in CookieAuthenticationHandler.cs there is a cool function call OnCheckSlidingExpiration. I am wondering how should I use that function in my current application.

dotnet-aspnet-core-mvc
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The solution depends on what kind of application and design. If this is MCV or Razor Pages app then create a JavaScript timer that loads on every page which fires at X minutes. The logic does an AJAX HTTP GET to an action which resets the sliding expiration.


1 Vote 1 ·

Thanks for the response. I'm using MVC and Razor Pages is part of my view. I understand is that cookies I've created is non persistent and ticket in the cookies will be expired within 20 mins due to the ExpireTimeSpan.

Thus I am wondering, is there any way etc a controller to keep track of the ticket's expiring time, if so the controller shall get a new token via OpenID Connect (not sure I got the flow correct). I did an experiment on the JavaScript timer, it could be dangerous if the page reload while the user is actually doing something; changes of restart to default.

Keep with more suggestion as I've run out of brain juice!

0 Votes 0 ·

An AJAX request will not refresh the page. The good news is an AJAX request will send the authentication cookie to the web application.

Controllers are stateless and are only active for the brief time custom code runs. Controller do not keep track of clients. Unfortunately, I tried to add JavaScript code to this comment but the forum will not allow the code for some reason.

2 Votes 2 ·
Show more comments

0 Answers