4

Any good way to preserve ASP.NET Application state across restarts?

I want to be able to set some values restart the app and have them still be there. I want to primarily do this for small "throw-away" test web apps that don't even need a database.

Is there some way to do it with static members and serialization? web cache?

UPDATE:
Application should be able to update these values.
Values could be custom objects like:

public class Person    
{  
  public string FirstName { get; set; }  
  public string LastName { get; set; }      
}  
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
  • How about storing these values in the web.config file? – John Saunders Aug 14 '09 at 18:58
  • What if the value is a small object graph... would that persist to the web.config? never tried that before. – BuddyJoe Aug 14 '09 at 18:59
  • 2
    Please clarify the question - do you need the application to be able to change these values and then have them appear when the application restarts? If so, then XML Serialize them out to some other XML file, then read them in when the application starts. – John Saunders Aug 14 '09 at 19:01
  • I'm thinking that might be the only way... unless someone comes up with some Application or Cache trick that I don't know about. – BuddyJoe Aug 14 '09 at 19:06

3 Answers3

2

Why not just use the ASP.NET State Service:

http://msdn.microsoft.com/en-us/library/ms972429.aspx

Am I missing something?

Keith Adler
  • 20,880
  • 28
  • 119
  • 189
1

You need some sort of persistent data storage, whether that's a database, xml files or something else.

You might be interested in the SimpleRepository with SqlLite from SubSonic which gets pretty close to what you describe.

John Sheehan
  • 77,456
  • 30
  • 160
  • 194
  • I'm trying to go a tad bit lighter. But I did SimpleRepo with SQLite yesterday. I wonder if serialize to XML is the only other way besides db4o and subsonic. – BuddyJoe Aug 14 '09 at 19:05
0

I believe that you can store the ASP .NET session in a SQL Server Server database. I'd imagine that would persist it across application restarts, or even shutdowns/reboots.

John B
  • 20,062
  • 35
  • 120
  • 170