Validation of viewstate MAC failed.

By | May 12, 2009

A very popular error, so popular and in so many places still unresolved. I spent a while trying to track down what was causing this error on my new hosting environment. I felt it would be a great idea to go ahead and repost my successful solution. I first did a hefty bit of searching on Google of course. Going through dozens of blogs and forums that seemed to all have similar answers for how to solve it. Turn off event validation they would say! Everything I read on that was telling me it would be a security nightmare to have a public application with page validateRequest=”false” enableEventValidation=”false” viewStateEncryptionMode=”never” in your web config file. I tried it anyway and I still got “Validation of viewstate MAC failed.” and I was so frustrated!

I kept searching until I found that generated a machine key and the xml required for my web config file. I put that in there an set the page attribute enableViewStateMac to true and uploaded my changes. I waited, 5 minutes no error, 5 hours no error, 24 hours no error. I exclaimed with joy when I could refresh my page after being idle a while and not see that terrible error. I hope this helps out someone else as I spent way to long tracking down an answer to this problem.

7 thoughts on “Validation of viewstate MAC failed.

  1. A Canter

    Are you running a web farm or just a single web server. here is my web.config. stil getting the same error

    Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

  2. Stephen


    When adding the generated key, the error has gone but i can’t login and keep on saying wrong password. Check it on database and password i entered was correct.

    Please reply.


  3. sosuke Post author

    I think you must have some other problems going on other than the Viewstate MAC failed error.

  4. sosuke Post author

    @A Canter
    Honestly I’m not sure if the shared hosting is on a web farm but I think not. I think the deal was the IIS pool was filling up and the server key was resetting or something sounding equally strange. I’ve only got guesses sorry.

  5. Henk-Jan


    This exception is also thrown if the apppool is flushed. This typically happens when a page is kept idle for a prolongued time.

    In this scenario the applicition that created the form was reset, thus invalidating all open forms. (the app that sent the controls is no longer valid.)

    a possible fix is to increase the interval between appool flushes.

  6. Zach

    Thanks ALOT!!! I followed the same suggestions you did and had the same luck you did. Then, I found your post and tried what worked for you and…finally!!! Thanks again.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.