This post originated from an RSS feed registered with .NET Buzz
by Scott Hanselman.
Original Post: A multi-request-safe ViewState Persister
Feed Title: Scott Hanselman's ComputerZen.com
Feed URL: http://radio-weblogs.com/0106747/rss.xml
Feed Description: Scott Hanselman's ComputerZen.com is a .NET/WebServices/XML Weblog. I offer details of obscurities (internals of ASP.NET, WebServices, XML, etc) and best practices from real world scenarios.
He stores a GUID in the ViewState hidden field, and sticks the bloated ViewState in
a temp file on the server. It doesn't solve the problem when running multiple
web servers while using stateless balancing (meaning: NOT using sticky sessions/node
affinity) but it's the most elegant and complete solution I've seen yet and should
work great on a single web server.
A few questions I have though:
When do the files get cleaned up and how often? Do you clean up old ones in a background
thread within ASP.NET or a separate Windows Service? Thought: I wonder
if you could delete them after immediately after the Load? You wouldn't
be able to RE-post data, but it'd be cleaner, no?
GUID generation is very expensive, and can really slow you down under load.
I wonder if it would be faster/easier to have a single long and use InterlockedIncrement or
InterlockedIncrement64 to safely increase the value on each call
until it overflows and you start again at 0.