Url remapping could be the source of your ViewState validation woes!

At work, we’re preparing a new release of the website, and came across an issue regarding ViewState validation. You may (or hopefully may not) have come across the following error before:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Or the even less helpful:

Unable to validate data.
Now originally, I thought this was something to do width MAC validation of the ViewState. But this is on a local machine, not a web farm. I shouldn’t need to worry about the MachineKey because of that. Hmmm…

Now, this only happens on two of our critical landing pages, which again was odd. They all inherit from the same base type, they all do exactly the same thing, albeit with different textual copy, so why would it happen?

Turns out, its our dynamic url remapping. When we do a Server.Transfer the ViewState validation fails, because the target page is not the same url as the remapped page we came from. The solution is simple, change the Form.Action property of the page to point to the remapped page:

protected new void Page_Load(object sender, EventArgs e)
base.Page_Load(sender, e);

Form.Action = "/{remapped-url-here}.aspx";
Code language: JavaScript (javascript)

Quite obvious now I think about it.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

RazorEngine v2RazorEngine v2

What’s new in RazorEngine v2?RazorEngine v1.2 has had some great feedback and certainly allowed us a good architecture to build from. It was a little too complex to configure different

Epic Fan-ArtEpic Fan-Art

Another daily search on Deviantart, and I found two gems, which are pretty damn impressive: SonicSuper_Sonic_by_MRi Source: Sonic by =gureiduson and Super Sonic by *MRi. Damn, if only I could