Getting signed out on live site after AppPool recycle
See original GitHub issueOn my live site after the AppPool is recycled I get Signed Out, the sign in code is something like this:
var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, id.ToString(CultureInfo.InvariantCulture)) },
CookieAuthenticationDefaults.AuthenticationScheme,
ClaimTypes.Name,
ClaimTypes.Role);
var authProps = new AuthenticationProperties { IsPersistent = rememberMe };
if (rememberMe)
{
authProps.ExpiresUtc = DateTimeOffset.UtcNow.AddMonths(1);
}
HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(identity),
authProps);
I’m signed out but in the browser dev tools I can see the cookie:
Name: .AspNetCore.Cookies
and it has expires 1 month
later: 2023-06-03T11:29:35.696Z
,
Domain: www.mysite.com, SameSite: Lax, Priority: Medium
This only happens on the live site, on localhost I can recycle, restart iis, and I stay logged in.
.NET Version
7
Anything else?
Site published on Shared Hosting Server
Issue Analytics
- State:
- Created 5 months ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
why on my live environment users will be logged-out if i do ...
Take a look to the session mode. By default, session mode is "InProc". So, when the app pool is recycled the session server...
Read more >iis - What is the effect of stopping an AppPool on currently ...
It is my understanding that asking an AppPool in IIS to recycle will give currently active requests 90 seconds to complete before they...
Read more >Solved: App Pool Recycling.... affect on current Users??
Hi, I need to schedule an "App Pool" recycle for about 5pm due to memory leak which I am sorting, but obviously will...
Read more >Application pool hangs until reboot - Microsoft Q&A
This application pool cannot be recovered on runtime recycling or restarting the pool, and only recovers if we reboot the server. We don't...
Read more >Web Connection Error After IIS App Pool Recycle
We get calls against our web service every second and so there are a lot of them logged. What causes this and how...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, somewhere your host will let you persist data.
Your encryption keys are being stored in memory and lost when you recycle, it can no longer decrypt the old cookie. (Check your logs). You need to store them outside of the app. https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview