1

I am getting the notorious error of

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

After extensive searching, I cannot find anything that solves my particular issue. I am using URL Routing in .NET 4, but I am NOT using MVC. All of the problems/solutions I have found that are similar (due to the URL routing) provide solutions in MVC, but not in regular ASP.NET Web Forms.

The Stack Overflow question here notes:

It seems to be related to the number of sub-paths in the url. If there are at least 2 sub-paths the viewstate validation fails.

In testing this theory, I was able to provide a quick and dirty work-around by simply changing my route from

Module/Search/Results

to

Module/SearchResults

which has temporarily solved the issue, however, none of the answers in that post helped at all.

Something interesting I found, the error can be reproduced in IE9, but not in Chrome 24.0.1313.52m. This lead me to believe that this error is browser specific so I tried setting NoCache for my site, but to no avail, Chrome still worked and IE9 still threw the ViewState error.

In order to reproduce the problem, here are some key factors to my environment:

Windows 7 64-bit
IIS 6.1 SP 1
Local Web Project (VS 2010)
Nested Master Pages (3 levels)
URL Routing (defined in Global.asax)
Page contains a GridView with a TemplateField.  
GridView has PagerSettings defined.
Links causing the error are within the TemplateField.
Links outside of the GridView do not cause the error.

The steps to reproduce are as follows:

User browses to page "~/Module/Search/Results" (from link or directly doesn't matter)
User clicks on a button that posts back and causes a redirect to another page "~/Module/DoSomething"
User presses the Back button in the browser which takes them back to "~/Module/Search/Results"
User then proceeds to press a button that causes a post-back which immediately causes the error.

UPDATE: Added information in the key factors regarding the layout of the page.

How can I solve this issue for all browsers so that I can have 2 or more sub-paths in the URL of a web page without causing the error when the user comes back to the page and then generates another post back?

Community
  • 1
  • 1
Aaron Hawkins
  • 2,611
  • 1
  • 20
  • 24
  • I managed to find this: http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx. Does that help (it relates to webforms). – Simon Whitehead Jan 22 '13 at 22:48
  • Unfortunately, no. It doesn't appear to be an issue where the user is pressing the button before the ViewState loads (I have given plenty of time to load). However, setting EnableViewStateMac to false does produce the error "The state information is invalid for this page and might be corrupted." as your link suggests at the beginning, but the rest does not appear to be applicable. (tried the base page and other suggestions from your link) – Aaron Hawkins Jan 22 '13 at 23:15

1 Answers1

0

I figured it out!

While attempting to solve an issue where I was getting the error

Microsoft JScript runtime error: 'WebForm_FireDefaultButton' is undefined

I found an article that said that I needed to add the following to the top of my routes table

routes.Ignore("{resource}.axd/{*pathInfo}");

This seems to have resolved both the issue I was looking for and the issue in this question.

Aaron Hawkins
  • 2,611
  • 1
  • 20
  • 24