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?
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?
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.