Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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)

share|improve this answer
    
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 –  Curt Dec 15 '10 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 '10 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. –  Curt Dec 16 '10 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 '10 at 22:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.