Validation of viewstate MAC failed On windows server

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster

some general errors you may face , when you earn dedicated server with windows server and host your website applications on IIS service is

					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.


Why i’m seeing Validation of viewstate MAC failed

The ViewState is a mechanism built in to the ASP.NET platform for persisting elements of the user interface and other data across successive requests. The data to be persisted is serialized by the server and transmitted via a hidden form field.

This kind of error caused by worker process or by server IIS recycling the process.The nature of ASP.NET process is to encrypt the viewstate by using Autogenerated Key when the process spins up ,The problem comes when a client (browser) sends the request with a viewstate encrypted with the key generated by another worker process. Since the key is different, ASP.NET will not be able to decrypt the viewstate and it will throw the above error.

How to solve ASP.NET Validation of viewstate MAC failed

There are several steps or options that you might workaround to solve the issue

  1. Host your site on a server where the application pools never recycle! Obviously, this is impossible.
  2. Disable ViewstateMac by putting this “enableViewStateMac=”false“” in your web.config on Pages tag under system.web tag. Please note that this step is not 100% secure “and NOT recommended”.
  3. Configure ASP.NET to not use Auto-Generated Key but rather a predefined key. This is the perfect and secure method .

To generate your key by yourself use Windows Shell

and then your web.config should like

					<machineKey validationKey=”08CE6B478DCE73……….E566D8AC5D1C045BA60″

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Related Posts