Welcome to WebmasterWorld Guest from 35.153.135.60

Forum Moderators: ocean10000

Message Too Old, No Replies

The Dreaded ViewState Error

     
9:18 pm on Apr 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


So I had a client update their website which is built in .net and now I get this whenever I try to execute an aspx page.

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.

I DID do research before I posted here so please don't post any links about changing the <pages> section of my web.config because I already tried it. Does anyone have any ideas about how I can troubleshoot this?

Couple tid bits. This is a stand alone Win 2k8 r2 server running .net 3.5 (although I think the site still works on 2. something) Any thoughts?
9:32 pm on Apr 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


If you tried the <pages> stuff, it's probably a code issue. Obviously going to be hard to figure out, but you can start by narrowing it down to any controls that are used/created OnLoad, OnPreInit, etc.
9:51 pm on Apr 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


So you're saying create a blank page and then start adding controls to it until it breaks?
1:37 pm on Apr 21, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


I am going to assume you have tried these already.
<pages renderAllHiddenFieldsAtTopOfForm="false" /> <-- this would fix it if it wasn't finished loading the page before the postback was triggered.

<pages enableViewStateMac="false" /> <-- This turns off the checksum checks of the viewstate data when it is posted back.

<pages MaxPageStateFieldLength="2024" /> <-- split the ViewState's single hidden field into several, to work around some proxie/firewall issues with large hidden fields.

Have you checked if you have two nested forms on the page? This is another common cause of this due to how easy it is to do with master pages.
1:53 pm on Apr 21, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I tried the pages thing. The login page (where I'm getting the error) has no master page. I also tried updating to 3.5 and adding a machine key. Any other ideas?
9:13 pm on Apr 21, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Are there any other form fields on the page or anything else that saves to the ViewState?
9:18 pm on Apr 21, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


If your page is only a few hundred lines long, I wouldn't mind taking a look at it.
10:01 pm on Apr 21, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


I can post the whole thing maybe but I noticed this.

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExMTAwMzYyNDdkZC+DL9vIjZGvVNEwSpcgEqvHmaVM" />

Would that last input have anything to do with it? Could I just remove it? If not, then I'll post my page, I just don't like to do that because I hate it when other people just post a page and say "this is broken fix it for me" :).

Update: when I removed them, then nothing happened when I clicked login. I've never worked with anything like this in .net so any help would be great!
8:57 pm on Apr 22, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


Those fields are actually auto-generated by .NET, and are what help with transitioning data during Postbacks. The __VIEWSTATE field specifically holds the encrypted data that needs to persist through to the page upon postback (e.g. clicking a Submit button, clicking a LinkButton, etc.). In a nutshell, don't mess with those inputs :)
9:00 pm on Apr 22, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


These inputs where actually in the aspx file.
2:17 pm on Apr 23, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:864
votes: 3


Those hidden inputs should not be in the raw unprocessed aspx file, if it is this might be part of the problem.
1:35 pm on Apr 25, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


But when I remove them, then the page does not do anything when you click submit. Any ideas why?
1:45 am on Apr 26, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


Do you have an OnClick event specified for your submit button?
12:54 pm on Apr 26, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


No, the form tag is where this happens i.e. <form action="login.aspx.vb">
3:53 pm on Apr 26, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 12, 2002
posts:1482
votes: 0


If your Submit button is a <asp:Button />, you need to have an OnClick event which corresponds to a method in the code-behind. In this method you "do stuff" (save the data entered in the form, etc.)

[msdn.microsoft.com...]