Asp.net core identity Logging in each time a user visits the site?

Viewed 39

I am working on an asp.net core app with identity authentication, and I need the user to log in each time they visit the site, so how could I do so?

1 Answers

You cannot track if the user has closed its browser. All you can do is set a sliding interval that is very low. You will log the user out if it hasn't made any requests within that sliding interval.

In your startup/program you need to add to the cookie options something like

ExpireTimeSpan = TimeSpan.FromMinutes(5),
SlidingExpiration = true,

Do be careful, because if the user has the webpage open, but has been inactive for (in this case 5 minutes) he will need to log back in. This might bring some user experience issues.

Related