{"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

\"Validation<\/a><\/p>\n

Next open your web.config file. Add the applicationName attribute to your provider declaration(s). You should set the applicationName attribute equal to \u201c\/\u201d to match the \u201c\/\u201d fields in your aspnet_Applications (dbo) table. An example is provided below:<\/p>\n

<roleManager<\/span> enabled<\/span>=”true” defaultProvider<\/span>=”CustomizedRoleProvider”>
\n<providers<\/span>>
\n<add<\/span> name<\/span>=”CustomizedRoleProvider”
\ntype<\/span>=”System.Web.Security.SqlRoleProvider”
\nconnectionStringName<\/span>=”MyConnectionString”
\napplicationName<\/span>=”\/”<\/strong>
\n\/>
\n<\/providers<\/span>>
\n<\/roleManager<\/span>><\/p>\n

<membership<\/span> defaultProvider<\/span>=”CustomizedMembershipProvider”>
\n<providers<\/span>>
\n<add<\/span> name<\/span>=”CustomizedMembershipProvider”
\ntype<\/span>=”System.Web.Security.SqlMembershipProvider”
\nconnectionStringName<\/span>=”MyConnectionString”
\napplicationName<\/span>=”\/”<\/strong>
\nminRequiredPasswordLength<\/span>=”5″
\nminRequiredNonalphanumericCharacters<\/span>=”0″
\n\/>
\n<\/providers<\/span>>
\n<\/membership<\/span>><\/p>\n

Make sure you add the applicationName attribute to all your users, roles, profile, and\/or any other <providers> nodes in your web.config or you\u2019ll run into problems. In the example above I\u2019m using both the Role and Membership providers so I added it to both declarations.
\nOnce you declare the applicationName attribute, ASP.NET will always use that application name when writing and connecting to the ASP.NET application service database regardless of where your application resides.<\/p>\n

Steve Kozyk
\nCEO\/Founder ITegrity
\nskozyk[at]itegritygroup.com
\nwww.itegritygroup.com<\/p>\n","protected":false},"excerpt":{"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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,182,18],"tags":[29,179,180,181,173,50,171,134,136],"_links":{"self":[{"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/posts\/97"}],"collection":[{"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":1,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":3165,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/posts\/97\/revisions\/3165"}],"wp:attachment":[{"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itegritygroup.com\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}