0

We've recently moved all our sites from one server (IIS6) to a new server (IIS7) which has also involved changing all the DNS records. However, on some of the sites, when you make a post-back on certain pages, you get the following error:

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. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: 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.

At first I thought this may be a propogation issue with the site (Ie. its trying to post-back to the old server). However, the DNS records were changed over 2 weeks ago, so surely this cannot be the case.

Why would this error be occuring?

It might be worth noting, this error never occurred on the old server.

1 Answer 1

0

This issue can often be caused by having auto-generated <machineKey /> keys in your server's machine.config file. Each time your application starts afresh it will generate new keys. This invalidates any existing encrypted viewstate or forms authentication tickets.

Try setting the <machineKey /> validationKey and decryptionKey to fixed values. See the following link for more information:

How To: Configure MachineKey in ASP.NET 2.0 (MSDN)

4
  • Reading through this article I can see I need to run a function to return crypted values. However what value would I pass as the parameter for: ByVal argv() As String ? Thanks
    – Curtis
    Dec 15, 2010 at 15:41
  • @curt - From the article: "..to request a 32-byte key, pass 64 as a command line argument. If you do not specify an argument, the code returns a 128 hexadecimal character (64-byte) key.".
    – Kev
    Dec 15, 2010 at 16:14
  • thanks for your reply. So does that mean I need to put App.Main(64)? Thats not a valid 2-dimensional string is it? Sorry I don't quite follow, Thanks.
    – Curtis
    Dec 16, 2010 at 14:08
  • @curt - Not sure what you mean by a two dimensional string. The number represents the key length in bytes you want to generate depending on purpose. App.Main(64) will generate a 128 chr hex key [two characters per byte] you can use for the validationKey (SHA1) and App.Main(32) will generate a 64 chr hex key to be used for the decryptionKey (if using AES decryption).
    – Kev
    Dec 16, 2010 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .