locked
Viewstate validation Error RRS feed

  • Question

  • User1156238706 posted

    I have a website hosted on shared server, running on .Net version : 4.0.30319.34280

    I was initially getting 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. AutoGenerate cannot be used in a cluster.

    In order to fix it I added a <machineKey> section in my web.config, by following the steps mentioned at : https://support.microsoft.com/en-us/kb/312906

    Now I am getting the following error

    Unable to validate data.

    stack trace:

    [HttpException (0x80004005): Unable to validate data.]
       System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData) +1072
       System.Web.UI.Page.EncryptString(String s, Purpose purpose) +150
       System.Web.Handlers.AssemblyResourceLoader.FormatWebResourceUrl(String assemblyName, String resourceName, Int64 assemblyDate, Boolean htmlEncoded) +52
       System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrlInternal(Assembly assembly, String resourceName, Boolean htmlEncoded, Boolean forSubstitution, IScriptManager scriptManager, Boolean enableCdn) +662
       System.Web.Handlers.AssemblyResourceLoader.GetWebResourceUrl(Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager, Boolean enableCdn) +188
       System.Web.UI.ClientScriptManager.GetWebResourceUrl(Page owner, Type type, String resourceName, Boolean htmlEncoded, IScriptManager scriptManager, Boolean enableCdn) +99
       System.Web.UI.ClientScriptManager.RegisterClientScriptResource(Type type, String resourceName) +96
       System.Web.UI.WebControls.BaseValidator.RegisterValidatorCommonScript() +212
       System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +85
       System.Web.UI.Control.PreRenderRecursiveInternal() +88
       System.Web.UI.Control.PreRenderRecursiveInternal() +160
       System.Web.UI.Control.PreRenderRecursiveInternal() +160
       System.Web.UI.Control.PreRenderRecursiveInternal() +160
       System.Web.UI.Control.PreRenderRecursiveInternal() +160
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883
    

    Any help in solving would be appreciated.

    Friday, December 18, 2015 3:50 PM

Answers

  • User614698185 posted

    Hi Syed Khaleel,

    Welcome to ASP.NET Forums!

    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.

    Firstly, you should make sure the following preconditions are true:

    1. You aren't using a web farm.

    2. It appears when using built-in databound controls such as GridView, DetailsView or FormView which utilize “DataKeyNames”.

    3. It appears if you have a large page which loads slowly for any reason.

    Secondly, you could fix the error through following ways:

    1. Set enableEventValidation to false and viewStateEncryptionMode to Never as follows:

    <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

    2. Mark the form as disabled and then enable it in script once the load is complete, or you can disable the individual form elements and enable them once everything is loaded.

    3. Override the Render Event of the page to place the hidden fields for Encrypted Viewstate and Event validation on the top of the form.

    For more information,please refer to the document about Validation of viewstate MAC failed error.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 21, 2015 5:49 AM

All replies

  • User614698185 posted

    Hi Syed Khaleel,

    Welcome to ASP.NET Forums!

    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.

    Firstly, you should make sure the following preconditions are true:

    1. You aren't using a web farm.

    2. It appears when using built-in databound controls such as GridView, DetailsView or FormView which utilize “DataKeyNames”.

    3. It appears if you have a large page which loads slowly for any reason.

    Secondly, you could fix the error through following ways:

    1. Set enableEventValidation to false and viewStateEncryptionMode to Never as follows:

    <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

    2. Mark the form as disabled and then enable it in script once the load is complete, or you can disable the individual form elements and enable them once everything is loaded.

    3. Override the Render Event of the page to place the hidden fields for Encrypted Viewstate and Event validation on the top of the form.

    For more information,please refer to the document about Validation of viewstate MAC failed error.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 21, 2015 5:49 AM
  • User1156238706 posted

    thanks

    Wednesday, December 23, 2015 3:39 PM