ASP.NET MVC Validation of viewstate MAC failed error

Posted in MVC | ASP.NET | .NET 3.5 at Saturday, 13 December 2008 02:30 GMT Standard Time

If you get a Validation of viewstate MAC failed error on ASP.NET MVC, before trying to hard code your <machineKey attribute in web.config, disabling the keying of viewstate

  <pages enableViewStateMac="false" />

, or any other literature you may want to check if the page you are posting data from has two "<form" attributes (the one hard coded on the page and the one created with Html.BeginForm()). If you play with master templates and have to merge some MVC pages with tradicional ASP.NET you may get to that error.

It took me a while to find the solution...

Did this post save you some time? post it. I'm curious. :) thanks.

AddThis Social Bookmark Button

Sunday, 21 December 2008 06:15:28 (GMT Standard Time, UTC+00:00)
It sure did save me some time! Nice one, thanks!
Sunday, 28 December 2008 07:05:28 (GMT Standard Time, UTC+00:00)
I wasted a couple of hours trying to find the issue, you saved my life, thanks!
Lloyd Phillips
Monday, 29 December 2008 16:14:15 (GMT Standard Time, UTC+00:00)
Hi guys,
Nice to know that. It was just a minute to post it. I am glad it saved several hours of time...

Friday, 30 January 2009 00:03:50 (GMT Standard Time, UTC+00:00)

I got the same error when i tried to manipulate the masterpage for passing the viewdata from content page. However reverting back the master page to the orginal version solved my problem.
However, it took me a while to solve the problem !
Wednesday, 11 March 2009 05:42:38 (GMT Standard Time, UTC+00:00)
Thanks for the help. I've used this twice now. You'd think I'd learn! :)
Wednesday, 08 April 2009 07:09:59 (GMT Daylight Time, UTC+01:00)
Chalk me up as another person who ran into this issue. I spent hours trying to troubleshoot it...and thankfully stumbled onto your post here. THANK YOU! THANK YOU! THANK YOU!
Tuesday, 14 April 2009 15:07:00 (GMT Daylight Time, UTC+01:00)
Nice one. I was down to my last monitor after smashing several with my keyboard... then I found your post.
Monday, 27 April 2009 23:31:21 (GMT Daylight Time, UTC+01:00)
woot. you rock.
Friday, 22 May 2009 06:43:42 (GMT Daylight Time, UTC+01:00)
2 hours i spent on this. damn, i should have googled a lot earlier
Saturday, 20 June 2009 23:39:07 (GMT Daylight Time, UTC+01:00)
Thanks! Removing the auto-generated form tag from my master page fixed the problem.
Thursday, 02 July 2009 20:36:28 (GMT Daylight Time, UTC+01:00)
Thanks. this post saved a me lot of time.
Saturday, 11 July 2009 10:31:16 (GMT Daylight Time, UTC+01:00)
Thought "Nah, cant be. I'm going to turn it off anyway". Stupid form tags in the site.master were causing it!
I'm sure I have broken something now... but it works so...

Cheers for the annoying solution.
Friday, 31 July 2009 21:57:54 (GMT Daylight Time, UTC+01:00)
I tracked the cause of this error down in my Web app to the use of the default page. So if I go to:


This loads Default.aspx, right? That's good, but then when I click on one of the link buttons on my sidebar, I get this "Validation of viewstate MAC failed..." error. Why? Because the action doesn't match the app path:

[ViewStateException: Invalid viewstate.
Client IP:
ViewState: /snip=
Referer: http://localhost/MyWebApp/
Path: /MyWebApp/default.aspx]

Notice the disjuncture between / and /default.aspx. I'm certain this is the issue, because if I go straight to http://server/MyWebApp/Default.aspx, everything works properly.

I fixed this simply by setting EnableViewState="false" on the aspx page in question. This worked in spite of the fact that the form tag is actually on my master page. It also worked because I don't have anything functional on my Default.aspx page other than a stack of link buttons, so if you have a very active form on your Default.aspx, this might be a problem. Otherwise it's a pretty simple solution. All of my other folders and pages use explicit naming, so there are no issues with lack of view state there.

Hope this helps someone else resolve this issue as well!
Wednesday, 16 September 2009 12:16:54 (GMT Daylight Time, UTC+01:00)
Thanks very much... this is very useful post. I tried a lot of things before this.
Saturday, 31 October 2009 10:25:59 (GMT Standard Time, UTC+00:00)
Great post!!! You saved my honor :-)
Comments are closed.