I am trying to recognize users that have already visited my site (on my .NET Core server), and I've registered services.AddSession()
in my project.
I am using attribute above my controller methods like so [SessionRequirement]
and in the class that handles those requests, I check if session with a given ID exists and I create an entry for it in the database _httpContextAccessor.HttpContext.Session.Id
.
When I test my method with Postman I receive a cookie .AspNetCore.Session=SOME_VALUE
, but after restarting the server, when I call the method with the same cookie and check the session.Id it's different.
How can I make sure that the session will stay the same even after restarting app?
You should store a cookie on the browser such as hasVisited=true, though if they clear their cookies this will be lost. Session IDs will not persist and are not fit for this usage
For cookies: https://www.c-sharpcorner.com/article/asp-net-core-working-with-cookie/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.