Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.


WAO viewstate example providers revealed

04/06/2010Categories: WAO
Recently we have published an application optimization package - Web Application Optimizer (WAO), and a few of our users requested a short example on how to build a custom ViewState provider. We have built two sample providers - one for the "beginner level" and one for more advanced developers.

1. Session provider - beginner-level provider that saves the ViewState data to the session.
2. Memory provider - advanced-level provider that saves the ViewState data to the memory ( worker process).

Building custom ViewState provider is a rather simple process. The first thing you need to do is to create a class that inherits from the BasePageStatePersister (a WAO base class for all ViewState providers). BasePageStatePersister contains a few useful properties and methods that you should understand before building custom WAO view state provider, and these are:

1. StateKey – used as a key that needs to be stored to maintain view state between postbacks (can be overridden for custom functionality).
2. LoadStateKey – used to get previously saved key (can be overridden for custom functionality).
3. Load method – you should override this method and implement any custom "load" functionality here.
4. Save method – you should override this method and implement any custom "save" functionality here.
Note: You need to call the “base.Save();”to be sure that proper ViewState key is saved. For more details on "Load" and "Save" method implementations please refer to the sample providers source code.

1. When building your own ViewState providers keep in mind that if you are using custom storage (Cache, SQL, Memory, etc.) you need to release these resources after some time.
2. If you have custom properties implemented on any of the custom providers you can set them under the “customProperties” tag in the web.config's WAO ViewState section and they will be initialized when needed.
3. To add your custom provider to the ViewState provider configuration section please use the template below:

<add workingFolder="" sqlConnectionString="" name="MemoryProvider" type="MonoSoftware.Web.WAO.Providers.MemoryProvider, MonoSoftware.Web.WAO.Providers.MemoryProvider" customProperties="RecycleTime=5;ViewStateTimeout=30;" />
<add workingFolder="" sqlConnectionString="" name="SessionProvider"
type="MonoSoftware.Web.WAO.Providers.SessionProvider, MonoSoftware.Web.WAO.Providers.SessionProvider" customProperties="" />
<add customProperties="RecycleTime=5;ViewStateTimeout=30;" type="MonoSoftware.Web.WAO.Providers.MemoryProvider, MonoSoftware.Web.WAO.Providers.MemoryProvider" name="MemoryProvider" /><add type="MonoSoftware.Web.WAO.Providers.SessionProvider,MonoSoftware.Web.WAO.Providers.SessionProvider" name="SessionProvider" />
This content has not been rated yet.