question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting signed out on live site after AppPool recycle

See original GitHub issue

On 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:closed
  • Created 5 months ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Tratchercommented, May 3, 2023

Yes, somewhere your host will let you persist data.

1reaction
Tratchercommented, May 3, 2023

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found