This has been deprecated! Please see this post
After reading various old blog posts about moving the ViewState to the end of the page using an HttpModule, I decided to create an HttpModule to store the ViewState in memcached, eliminating the need to send the data back and forth to the client and stopping prying eyes from seeing the ViewState.
Halfway through writing the HttpModule, I discovered that Philip Rieck had already written a pluggable ViewState manipulation HttpModule, so I made a memcached plugin for it using the BeITMemcached client.
To get this up and running on your site, download the latest source from http://code.google.com/p/memcachedviewstatehttpmodule/ and follow these steps
1. Copy all the code from the Release folder into your web sites bin directory
2. Merge the xml below into your web.config and edit the memcached server addresses
<configuration>
<configSections>
<section name="beitmemcached" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<appSettings>
<add key="viewRestateStore" value="Assembly"/>
<add key="viewRestateStoreType" value="MemcachedViewStateStore.MemcachedViewStateStore,MemcachedViewStateStore"/>
</appSettings>
<beitmemcached>
<add key="ViewStateCache" value="127.0.0.1" />
</beitmemcached>
<system.web>
<httpModules>
<add name="viewrestate" type="NFission.Web.ViewRestateModule,NFission.Web.ViewRestate"/>
</httpModules>
</system.web>
</configuration>
3. That should be it. A couple of words of warning. I haven't used this in production yet, but will hopefully do so sometime in the next week. Also, I haven't distibuted the source for Philip Riecks HttpModule as I don't know the licence for it. I had to make a couple of minor changes to get it to work correctly
- I commented out the GZip stuff as I'm not using it
- changed line 72 of VsInFilter from Buffer.BlockCopy( this.dataBuffer, (int)position, buffer, offset, count); to Buffer.BlockCopy( this.dataBuffer, (int)position, buffer, offset, realCount);).
- changed line 16 of VsFilter from private const string ViewstateKey = "name=\"__VIEWSTATE\ value=\"";" to private const string ViewstateKey = "id=\"__VIEWSTATE\" value=\"";
I'm trying to get in touch with Philip to clear up the licence.
5 comments:
Im having a problem reading the viewstate back in. I think it's the regex. What is __VIEWSTATE=%24filterd%24(?token[^&]*) meant to match? shouldn't it be id="__VIEWSTATE" value="$filter$"
Does the sample project run for you? The counter should increment when you click the button.
No the sample on doesn't work. I had to create a different regular expression and it works. For a start there is no = decoded string. I have no idea how the current regex would work
I wonder if there's perhaps some difference in the Framework versions we're running which alters the format of teh viewstate element. On my VS 2008 / 3.5 machines the sample works correctly.
I haven't managed to get in contact with Philip Rieck so I can't release modifications to his code. I'll have to write my own code for reading the ViewState in and out at some point.
Sorry, I'm not as easy to contact as I should be.
You are free to use/modify/redistribute the code without any restrictions whatsoever. Heck, you can claim it as your own if you're brave. A bit of credit is never turned down though.
You can even roll it into your code space and take it over. In fact, that's probably the only way it will live.
If you want to talk further at all, you can email me at gmail as Philip dot Rieck.
Post a Comment