CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • ASP.NET Validation of viewstate MAC failed.

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    177
  • Date Created
    Friday, July 27, 2012
  • Last Updated
    Friday, July 27, 2012
  • This Article Has been Viewed
    1852 times
  • Short Desc
    Validation of viewstate MAC failed will happen if you do not have a Machine Key for your site. Follow these simple instructions to generate a Machine Key for your ASP.NET site.
  • Details
    When you are developing your ASP.NET application on a server that is shared, or for better words, on a clustered environments or web farm, then you might experience 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.
  • Recreate Issue
    To recreate this issue:

    This issue will happen if you do not have a Machine Key for your site.
  • Resolve Issue
    To resolve this issue.

    Creating a Machine Key

    The database.config and encryption.config files are saved in an encrypted form,
    so that your connection string and encryption key remain protected. If you are installing
    AbleCommerce to a web farm or clustered environment, you must take additional steps so that
    this file encryption will work properly.

    You may experience a problem with having to continuously login.
    You may also experience MAC validation errors.
    If this happens, follow the steps below:

    #1: Visit this URL: http://aspnetresources.com/tools/keycreator.aspx«

    #2: The default values for key generation are correct (64/24/SHA1), click Generate

    #3: Copy the resulting machine key.

    #4: Open the web.config for the store, and paste the copied machine key after the line that says

    <system.web>

    Save web.config and restart the IIS application service.

    When you don’t specify the machine key in web.config, ASPNET automatically generates one for the application.
    If something causes the application to recycle, the key is regenerated.
    If the application recycles between requests, then any data that was downloaded by the browser was
    recorded with the first key, and validated with the second.
    This turns into the MAC validation error, because the keys are not the same.
    This is why the error mentions clustered environments, because the same issue occurs if
    you move from one server to another between requests.

    When you set the key in the web.config file, ASPNET uses this key rather than auto generating.
    That ensures that even if an application recycle takes place, the validation will be correct.
    This is used for things like session cookies, authentication, viewstate validation,
    event validation, and so on.

    For more information on this article, please refer to its source.
    @ help.ablecommerce.com«