Persisting application state in ASP.NET website

1k views Asked by At

I am storing some web site settings for my ASP.NET website in the application state. I have also initialized the state in the Application_Start() method. Specific users can change these settings, but after a period of time, the settings are reverting back to the values with which they were initialized in the Application_Start() method, even though the server is constantly running.

Any idea why this is happening? Does the application get shut down if it does not receive any requests for a specific period of time?

Thanks in advance.

3

There are 3 answers

0
jrummell On BEST ANSWER

Does the application get shut down if it does not receive any requests for a specific period of time?

Yes, by default the application pool will shut down after a period of inactivity. See Common reasons why your application pool may unexpectedly recycle for more information.

If you need to keep state across application pool recycle events, you should persist your state in a database or in App_Data.

0
Shyju On

Application state is stored in memory of webserver. Your changes made by users are lost because the App Pool recycled and hence the application variables data are gone.

Any changes to the web.config / global.asax will also restart the application.

If you want to keep those changes your users made, you may need to store it into a persistant medium (Database) and load it from there on application start up.

This link gives you more info about Application states

0
Jean-François Côté On

Yes, after a period of inactivity, the application pool will shut down. If you need some variable to stay alive, you should consider putting them in the web.config or in the database, it will be safer and more logical.