views:

231

answers:

2

So I've done my best to minimize my viewstate on my ASP.net ajax application, http compression, disabling viewstate in hidden fields, but would like to go further. So after researching it seems that there are two approaches

a) use the ASP.net 1.x way which uses LoadPageStateFromPersistenceMedium

b) or use the ASP.net 2.x way SessionPageStatePersister

So B doesn't look good because if I understand it correctly the viewstate would be linked to the session id, and since my session can expire for any number of reasons I want don't want this.

So what's the best approach to saving viewstate on the server that does depend on sessions?

If it's LoadPageStateFromPersistenceMedium and uses hidden fields, then how do I inject a hidden field with a random id into a page?

How do I determine when it's time to clear viewstate files on the server?

A: 

I think you should seriously consider the Session option. It's optimal on resources and even if the Session expires if your Auth mechanism is alighed to session timeout it's not an issue.

http://professionalaspnet.com/archive/2006/12/09/Move-the-ViewState-to-Session-and-eliminate-page-bloat.aspx

As a fallback you could implement a Page base that puts the Session ID into the ViewState, checks it on postback and if it's different than does some action to recover.

The only other option you have would be to create your own PageAdapter that uses the DB or some other data store.

Nissan Fan
We use forms authentication so I don't think its aligned to session timeout.what do you think of this approach inhttp://aspnet.4guysfromrolla.com/articles/011707-1.aspxwhere they made their own FileSystemPageStatePersister class.Do you think that would work better for example on a web farm?
Tuviah
Just use SQL Server for Session persistance or use the service on a single machine and it will work flawlessly on a web farm.
Nissan Fan
Another problem is that sessions expire after 20 minutes by default. Sure we could expand it but this will just take more memory..also have problems with user clicking back and forth multiple times, switching between browsers..or removing their cookies.I've read that it's possible to write your own PageStatePersister which would generate a guid, attach that to a hidden field on a page, and then save viewstate into a database or file using the guid as the key.would this be a better approach?
Tuviah
The session mechanism in SQL State Service is really good. You could roll your own, but at the end of the day setting the forms auth ticket timeout and session to the same time period is a standard way to proceed.
Nissan Fan
Tuviah, that is the exact mechanism Flesk Viewstate optimizer uses
Sameer Alibhai
A: 

How about trying Flesk ViewState Optimizer?

Has several options including storing in session, in database, etc.

Sameer Alibhai