Viewstate validation exceptions

  • This article describes the most common scenarios and troubleshooting tips for the exceptions related to viewstate validation, which might appear in Sitecore log files.

    It is important to note that these exceptions are not particularly related to Sitecore, they are applicable to all ASP.NET applications.

  • Message: "The state information is invalid for this page and might be corrupted."

    Stacktrace example:

    Exception: System.Web.HttpException
    Message: The state information is invalid for this page and might be corrupted.
    Source: System.Web
       at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
       at System.Web.UI.HiddenFieldPageStatePersister.Load()
       at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
       at System.Web.UI.Page.LoadAllState()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Nested Exception

  • Message: "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".

    Stacktrace example:

    Exception: System.Web.HttpException
    Message: 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.
    Source: System.Web
       at System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState)
       at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose)
       at System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose)
       at System.Web.UI.HiddenFieldPageStatePersister.Load()
       at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
       at System.Web.UI.Page.LoadAllState()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Nested Exception

  • Message: "The client disconnected."

    Stacktrace example:

    Message: The client disconnected.
    Source: System.Web
       at System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState)
       at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()
       at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
       at System.Web.UI.WebControls.TextBox.LoadPostData(String postDataKey, NameValueCollection postCollection)
       at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       at System.Web.UI.Page.ProcessRequest()
       at System.Web.UI.Page.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

    Nested Exception

    1. If MAC validation is enabled, make sure that machineKey is statically set. Otherwise, an error could be raised in case machineKey is regenerated (for example, after IIS reboot or application pool recycle) when user browsing the website. After the machineKey is changed, the next postback will cause MAC validation to fail.
    2. In multi-instance environments with enabled MAC validation, make sure that machineKeys, “validation”, and “decryption” attributes are the same on all involved instances.
    3. Configure the MaxPageStateFieldLength attribute in the pages section of the web.config file to split viewstate into chunks (several hidden fields). When the size of the viewstate is huge, viewstate validation might fail due to hidden fields being truncated by some browsers (typically browsers on mobile devices) when it exceeds some value. Hidden fields with very long values might also be truncated by certain antivirus software/routers/proxies/etc.
    4. Make sure that 3.5 .NET framework SP 1 or above is installed. This is relevant if you use controls such as GridView, DetailsView or FormView, which utilize “DataKeyNames”. Use the following link to find additional information about this particular scenario.
    5. Exception #3 can occur when viewstate validation fails and a user/browser for some reason disconnects before the server has finished processing the request. Applying the solutions 1-4 reduces the chance that such exceptions will appear in the log file.

Applies to:

CMS 6.0 - 6.6

February 25, 2014
April 07, 2020

Reference number:

346083, 331179, 359222