Once in a while I'm getting a lot of requests that post an invalid viewstate (sometimes entire e-mails - what are they thinking?). Since I'm kind of fed up logging all this spam, I decided to put together a little HTTP module that temporarily stops processing such requests. To use this, head over to the toolbox and get the latest version of Wilco.Web. Add the library to your website and add the following to your web.config:
1
2
3
|
<httpModules>
<add name="ViewStateDosBan" type="Wilco.Web.ViewStateDosBanModule, Wilco.Web" />
</httpModules>
|
In a nutshell, the module keeps a list of requests which resulted in a ViewStateException. This list is stored in the cache with an absolute expiration time of 2 minutes. When a request is made by a client that already resulted in at least 5 ViewStateExceptions, the request is ended immediately.