We had a fresh install of Windows 2008 and Visual Studio 2010 on a developers machine that was getting this error when trying to access a MVC 2.0 .Net 4.0 website hosted locally on IIS7. Various fixes talk about making sure there is a default document, and also about turning on directory browsing, but neither of those work. (MVC 2.0 does not need a default document specified).
The issue was that .Net framework 4.0 had not installed correctly, so here is what you need to do to fix it.
1.) Run a command prompt as Administrator.
2.) Copy and paste the following text “C:WindowsMicrosoft.NETFramework64v4.0.30319aspnet_regiis.exe -i”
This is assuming that you have already installed MVC 2.0 And .Net Framework 4.0 , but not in the correct order.
We were testing the deployment of a website onto 2 load balanced IIS 7 servers the other day, and the sites were loading fine. the next morning one of the testers was reporting an erorr on the website that said ”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” . We looked at the error and realised that we need to create a static machinekey and add it into the web.config of both our IIS7 web servers to fix the issue.
We did this, but when we refreshed the page, we were still getting the same error on the website. We tried hitting the sites in new browsers and they loaded fine. What we realised was that becuase we hadn’t shut down the browser, it was still using the old machine key, and as it didn’t match the autogenerated one on the webserver that the browser was hitting, we would get this error.
The steps to fix this are as follows:
1. Generate a new static machinekey and enter it into both web.config files.
2. Open a new browser window to test.
Here is a sample machinekey entry for your web.config file
<machineKey validationKey=’3AE041467624C0947FE562E2DBE6122B532FBC4AA9845AE3D82EC6AC473104EA40A27F8E89BADDAEE44B1F7582FC47299B674ED1FD2DDE1368710504EB2C54C1′ decryptionKey=’2FC79A393A5A463F82D38828F43ED7D030C418B448C9E76C’ validation=’SHA1′/>