Validation of viewstate MAC failed

Programming, error messages and sample code
viewstate mac
 
The Machine Key is configured "AutoGenerate,IsolateApps" default, once the application pool restart, a new decryption key will be generated, if you submit a PostBack from the website with the old decryption key, you may get the below error message on your website:

 
Solutions:
 
a). find your application pool log from Control Panel > Advance > Pool Manager, check if the app pool is recycled/restarted frequently, figure out why the app pool is recycled/restarted.
If the app pool is recycled due to reaching its private memory limit, you can upgrade the hosting plan or buy additional RAM from Add-Ons to increase the memory limit. Or please debug your website locally to reduce memory usage.
 
 
b). explicitly specify the machine key in the web.config file, your website will read the decryption key from the web.config instead of being generated automatically every time the application starts.
For example, put this in your web.config, it will work properly.
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <machineKey decryptionKey="A2963AFC6A885272300FB4E9014A8DE6B6626C42311BF7EF" validationKey="CDCF154A4350B577552FD0A56D0F73B3D975F18EDF10044DC3FB0DD1CE09120B4AA3224EE580E05CF45F497291EA7AAF8DA791E1A3914383A802C0FA12F2C0AE" />
    </system.web>
</configuration>
To generate your own decryption key, please go to your local IIS Manager > specific site > Machine Key > Generate Keys
 
viewstate mac
 
 
c). do not use ViewState Validation, disable it in the web.config file
 
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <pages enableViewStateMac="false" />
    </system.web>
</configuration>
We do not recommend this, as you could introduce security holes.