In this article we will learn you how to solve ASP.NET Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster
Once you earn dedicated server with windows server and host your website applications on IIS service, you may face some general errors such as:
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.
Why I'm Seeing This Error?
View State is the mechanism to preserve the Value of the Page and Controls between round trips. It is a Page-Level State Management technique.
Normally this error happens because of aps.net worker process or by server IIS recycling the process. ASP.NET process is to encrypt the view state by using Auto generated Key when the process spins up, the problem comes when a client (browser) sends the request with a view state encrypted with the key generated by another worker process. As long as the key is different, ASP.NET will not be able to decrypt the view state and it will give the above error.
Solve ASP.NET Validation of Viewstate MAC Failed
Follow one of these options to solve the problem:
- Host your site on a server where the application pools never recycle! Certainly, this is impossible in Shared Hostings. You need a VPS server or dedicated server, where you can configure your own settings.
- Disable View state Mac , just run “enableViewStateMac=”false“” in your web.config on Pages tag under system.web tag.
- Configure ASP.NET to not use Auto-Generated Key but rather a predefined key.
- Generate your key by yourself using Windows Shell, then your web.config file should look like below: