This project is read-only.

ViewState handlers

Classes and utilities to handle Webforms ViewState

ViewStateHandlers is a set of classes and persisters to handle the persistence of ASP.NET ViewState in a different ways.

Current persisters:
  • Compressed Page ViewState (up to 60% smaller ViewState in page)!
  • ASP.NET Cache persister (out of page persister for small/medium traffic websites)


Add this to your Web.Config
 <sectionGroup name="viewStateHandlers">
      <!-- Important configuration with definition of persisters -->
      <section name="viewStatePersisters" type="Rioshu.Web.ViewStateHandlers.ViewStatePersistersConfigurationHandler" />
      <!-- Needed for compressed hidden field in page persister -->
      <section name="tinyPagePersister" type="Rioshu.Web.ViewStateHandlers.TinyPagePersisterConfigurationHandler"/>
      <!-- Needed for out of page ASP.NET cache persister -->
      <section name="cachePersister" type="Rioshu.Web.ViewStateHandlers.CachePersisterConfigurationHandler"/>

And later just configure your Persisters in the Web.Config


    <!-- Definition of persisters for viewstate storage, you need to define at least one and set its name in default -->
    <viewStatePersisters default="cachePersister">
        <!-- Compressed hidden field page persister -->
        <add name="pagePersister" type="Rioshu.Web.ViewStateHandlers.TinyPagePersister, Rioshu.Web.ViewStateHandlers" />
        <!-- Out of page ASP.NET cache persister -->
        <add name="cachePersister" type="Rioshu.Web.ViewStateHandlers.WebCachePersister, Rioshu.Web.ViewStateHandlers" />
      compressionType is the compression algorith to apply, GZip is default algorith, other options:
        * Zip : Using ICSharp Zip Compression
        * SevenZip : Using Seven Zip Compression
      fieldName is the hidden field name and id in the page with the compressed viewstate, default is __VSTATE
    <tinyPagePersister compressionType="GZip" fieldName="__VSTATE" />
      fieldName is the field name in the page with the viewstate id stored in the cache
      slideTime is the slide time or time out to keep the viewstate data in the cache if it is not used
    <cachePersister fieldName="__VSTATEID" slideTime="00:20:00" />

Finally just add a browser file to use the persister

  <browser refID="Default">
      <adapter controlType="System.Web.UI.Page"
               adapterType="Rioshu.Web.ViewStateHandlers.ViewStatePersisterAdapter, Rioshu.Web.ViewStateHandlers" />

Future enhacements

  • Out of page database persistence (SQL Server, SQLite?)
  • Out of page Server files persistence
  • Test cases!
  • Better documentation?

Last edited Aug 25, 2009 at 5:23 AM by cprieto, version 6