I get this error: Validation of viewstate MAC failed. when Editing my GridView control

Greetings everyone!
suddenly this error started appearing when I am running my web application, I have a GridView control, with editing enabled, once i click on the "edit" button on the gridview I get this error message:

"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 hope someone could help.
thanks in advance.
~salman~
salman_sulaiman_2008Asked:
Who is Participating?
 
RejojohnyConnect With a Mentor Commented:
have a look here ..

ASP.NET 2.0 and "Validation of ViewState Mac failed" exception
http://aspadvice.com/blogs/joteke/archive/2006/02/02/15011.aspx

from above link .....
It appears because GridView using DataKeyNames requires ViewState to be encrypted. And when ViewState is encrypted, Page adds  <input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" /> field just before closing of the <form> tag. But this hidden field might not bet yet rendered to the browser with long-running pages, and if you make a postback before it "gets down", browser initiates postback without this field (in form post collection)

End result is that if this field is omitted on postback, Page doesn't "know" that viewstate is encrypted and causes the prementioned Exception. E.g Page expects to be fully-loaded before you can make a postback. And by the way similar problem is with event validation since __EVENTVALIDATION field is also rendered on the end of the form.

A way to overcome the problem is to set in web.config
<pages enableEventValidation="false" viewStateEncryptionMode ="Never" />
Just note the security implications of these!

0
 
QPRCommented:
http://forums.asp.net/t/955145.aspx
discussed here with potential fix
0
 
salman_sulaiman_2008Author Commented:
Greetings QPR!
thanks for the reply mate!
I found one suggested solution but without much explaination on how to implement it, here what the one of the guys posted:
--------------------
Thanks for reply;

The Machine Key in Webconfig has solved the proble. The session issues we related to limitation on CPU usage on server that server admin has solved by removing the limitation.

I highly recommend anyone has this proble to try put the MachineKey on Web.config

Cheers

Moez
------------------------

so, I am wondernig now, how can I place  the machine key inside the web.config to solve my problem?

~salman~
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
salman_sulaiman_2008Author Commented:
Greetings QPR!
thanks for the reply mate!
I found one suggested solution but without much explaination on how to implement it, here what the one of the guys posted:
--------------------
Thanks for reply;

The Machine Key in Webconfig has solved the proble. The session issues we related to limitation on CPU usage on server that server admin has solved by removing the limitation.

I highly recommend anyone has this proble to try put the MachineKey on Web.config

Cheers

Moez
------------------------

so, I am wondernig now, how can I place  the machine key inside the web.config to solve my problem?

~salman~
0
 
salman_sulaiman_2008Author Commented:
Greetings Rejojohny!
thanks mate! I just read your commet  too, and it fixed the problem. But, if this way would raise up some security issues then can't we do it some other way, i read on the forum one guy suggesting to place the MachineKey inside the web.config, and another guy suggesting to Uninstall Framework and reinstall it again, but for now, placing that statement inside the web.config actually fixed the problem.
the thing is, I am developing this web application under Windows Vista, and I am wondering if upgrading to .NetFramework 3.0 and Vistual Studio 2008, would be a good idea to come over such debugging problems..? what do you think?
Best Wishes,
~salman~
0
 
salman_sulaiman_2008Author Commented:
Greetings Rejojohny!
thanks mate! I just read your commet  too, and it fixed the problem. But, if this way would raise up some security issues then can't we do it some other way, i read on the forum one guy suggesting to place the MachineKey inside the web.config, and another guy suggesting to Uninstall Framework and reinstall it again, but for now, placing that statement inside the web.config actually fixed the problem.
the thing is, I am developing this web application under Windows Vista, and I am wondering if upgrading to .NetFramework 3.0 and Vistual Studio 2008, would be a good idea to come over such debugging problems..? what do you think?
Best Wishes,
~salman~
0
All Courses

From novice to tech pro — start learning today.