{"id":97,"date":"2008-10-30T20:17:59","date_gmt":"2008-10-31T03:17:59","guid":{"rendered":"http:\/\/www.itegritygroup.com\/itegrity\/seo-web-development-blog\/?p=97"},"modified":"2011-01-09T01:20:11","modified_gmt":"2011-01-09T09:20:11","slug":"validation-viewstate-mac-failed","status":"publish","type":"post","link":"https:\/\/www.itegritygroup.com\/validation-viewstate-mac-failed\/","title":{"rendered":"Validation of Viewstate MAC Failed"},"content":{"rendered":"
The Validation of Viewstate MAC failed error commonly occurs when an ASP.NET application developer uses the Membership, Roles and\/or Profile Providers included with the .NET Framework. The usual scenario is the developer creates the application on their local machine and stores the project files in a local directory. When the developer copies or publishes the project files to another local directory or to a remote server, the login system doesn\u2019t appear to function properly.<\/p>\n
The solution is to manually add the applicationName attribute to the <providers> node of your web.config file and give it a value. By default ASP.NET auto generates the applicationName using your project\u2019s root directory path if the applicationName attribute isn\u2019t declared in your web.config. The applicationName is important because your ASP.NET Application Service database uses it in a number of tables. The applicationName is a relatively long string of characters and will look similar to: cea2acdb-97b7-4b58-ad12-22efg3bd582q.<\/p>\n
If you move your project to any other directory either local or remote, a new applicationName string will be auto generated and added to your ASP.NET Application Service database. Any new users, roles, or profiles you create will be tied to the new applicationName. Once you move your application to a new directory, any users, roles, or profile information you created while your project resided in your previous directory will not function or throw 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. Auto Generate cannot be used in a cluster.” Each time you move your project to a different directory you\u2019ll run into this problem.<\/p>\n
To solve this, first go to the Server Explorer in Visual Studio and open the database containing your ASP.NET Application Service database. Right click on the table named aspnet_Applications (dbo) and select \u201cShow Table Data\u201d. Look to see what your ApplicationName and LoweredApplicationName fields are named. It should be \u201c\/\u201d. If it\u2019s named anything other than \u201c\/\u201d, rename both fields \u201c\/\u201d as shown below.<\/p>\n