Share via


Logged out of ASP NET Core site on IIS after 5 minutes of inactivity

Question

Thursday, October 20, 2016 3:44 AM

Hi,

When running my ASP NET CORE MVC site on IIS I notice that after 5 minutes of no requests, I get logged out of the site (I'm using Identity with cookies authentication).

I suspected this being caused because of the app pool shutting down of inactivity, thus losing any session memory related to the user.

So when in Staging/Production environment, I replaced the InMemoryDatabase for a SqlServer. But I am still having this problem, and I see some weird exceptions of a key not being found in a key ring. I just want the cookies or whatever is needed to persist (either in the sql server or the drive).

These are the important files in the project.

Startup.cs

Program.cs

Log file when logged out

web.config

Login portion of the code

I apologize if I'm missing important details, let me know if I do. Thanks for reading. 

All replies (8)

Thursday, October 20, 2016 7:15 AM

Hi erandros,

I suspected this being caused because of the app pool shutting down of inactivity, thus losing any session memory related to the user.

Please check the Application Pool's Idle Time Out settings. When Idle Time Out is configured, a worker process will shut down after a specified period of inactivity, then all the data stored in memory will be lost.

Configure Idle Time-out Settings for an Application Pool (IIS 7)

I see some weird exceptions of a key not being found in a key ring

The exception indicates that the key your are using is wrong, you need to reuse the same key.

You can find how to reuse the same key in the following link.

http://stackoverflow.com/questions/34319802/mvc-6-webfarm-the-antiforgery-token-could-not-be-decrypted

Best Regards,

Jean


Thursday, October 20, 2016 1:18 PM

Hi,

I don't think Changing the time-out might be what I'm looking for, I want whatever session data is needed to persist.

I tried that stackoverflow answer, I included DataProtection code in Startup.cs:100, with no luck unfortunately.


Thursday, October 20, 2016 3:11 PM

Just a coding error on your part. you are setting the cookie expiration to a time in the past rather than the future. 

note: asp.net core does not use app pools nor is session stored in an app pools. your asp.net core is a separate application that IIS reverses proxies to. there is no idle shutdown to an asp.net core app like there was with old asp.net code app pools. IIS should start your core app on first request, and if it doesn't crash it will run until a reboot is done.


Thursday, October 20, 2016 3:49 PM

Bruce, when worker process recycles (ie due to idle timeout), it'll cause shutdown of the child dotnet.exe process...  If there are issues w/ the app where it doesn't handle dotnet.exe recycling well, this scenario could affect that.  Therefore, when hosting through IIS, all app pool settings for recycling will have effect on lifecycle of dotnet.exe.  Though, as you mentioned app pool worker process doesn't actually keep anything in its memory related to execution of Core apps... it's just an indirect effect (recycling w3wp.exe will recycle its child process, in this case dotnet.exe)


Thursday, October 20, 2016 4:05 PM

Bruce,

You mean in the Startup.cs or the login code (line number)? Can you show the correct implementation?

Btw, are you sure? This 5 minute expiration doesn't happen when running it on Visual Studio on Kestrel, only in IIS.


Friday, October 21, 2016 1:25 PM

Bump


Saturday, October 22, 2016 7:19 PM

Can you try this:

https://docs.asp.net/en/latest/publishing/iis.html#create-a-data-protection-registry-hive


Monday, October 31, 2016 3:59 PM

Thank you very much, I was looking for this solution for the las 2 weeks, I even gave up, and was wating for when asp.net core would have more information

I have a site, that I was tired of login in all the time

Re: Logged out of ASP NET Core site on IIS after 5 minutes of inactivity

10-20-2016 02:15 AM

Hi erandros,

erandros

I suspected this being caused because of the app pool shutting down of inactivity, thus losing any session memory related to the user.

Please check the Application Pool's Idle Time Out settings. When Idle Time Out is configured, a worker process will shut down after a specified period of inactivity, then all the data stored in memory will be lost.

Configure Idle Time-out Settings for an Application Pool (IIS 7)

I can not mark as answared becuase i did not started the post Just wrote to thank jean Sun