DevMania
DevMania

Reputation: 2341

what are the pitfalls of storing Viewstate in session or DB

I have read that you can do it, but would this really improve performance of the page, or would it bring more performance overhead?

Upvotes: 2

Views: 276

Answers (2)

triniMahn
triniMahn

Reputation: 278

Viewstate data is information about the page that is encrypted and serialized into a hidden tag on the page.

If you could store it in the session these are some of the problems/pitfalls:

  • The information still has to be encrypted/decrypted and serialized/deserialized from memory
  • If you have a lot of users and your session data is stored in process or even using a state server, you're going to max out the memory on these servers with viewstate data.
  • If you're using SQL Server for session state this obviously gets worse (see below).

If you could store it in SQL Server these would be some of the problems:

  • Again, information still has to be serialized/deserialized (not necessarily encrypted/decrypted since it's not output to the page), but in this case it has to be read/written from a SQL DB. You will incur overhead in both transmission to/from the DB and I/O when reading/writing from/to the DB.

Upvotes: 3

Phaedrus
Phaedrus

Reputation: 8421

Here's a good article by Scott Hanselman about storing ViewState information in the Session object:

Moving ViewState to the Session Object and more Wrongheadedness

Upvotes: 6

Related Questions