Asp.net Validation of viewstate MAC failed

前端 未结 16 1594
猫巷女王i
猫巷女王i 2020-12-02 20:12

I am receiving the following error at certain times on asp.net website.

 Sys.WebForms.PageRequestManagerServerErrorException: 
 Validation of viewstate MAC f         


        
相关标签:
16条回答
  • 2020-12-02 20:46

    I've experienced the same issue on our project. This Microsoft support web page helped me to find the cause. And this solution helped to sort out the issue.

    In my case the issue was around ViewStateUserKey as Page.ViewStateUserKey property had an incorrect value (Caused 4 in here). Deleting localhost certificates and recreating them by repairing IIS Expres as mentioned in here fixed the issue.

    0 讨论(0)
  • 2020-12-02 20:48

    This error message is normally displayed after you have published your website to the server.

    The main problem lies in the Application Pool you use for your website.

    Configure your website to use the proper .NET Framework version (i.e. v4.0) under the General section of the Application Pool related to your website.

    Under the Process Model, set the Identity value to Network Service.

    Close the dialog box and right-click your website and select Advanced Settings... from the Manage Website option of the content menu. In the dialog box, under General section, make sure you have selected the proper name of the Application Pool to be used.

    Your website should now run without any problem.

    Hope this helps you overcome this error.

    0 讨论(0)
  • 2020-12-02 20:48

    WHAT DID WORK FOR ME

    1. Search the web for "MachineKey generator"

    2. Go to one of the sites found and generate the Machine Key, that will look like... (the numbers are bigger)
      ...MachineKey
      validationKey="0EF6C03C11FC...63EAE6A00F0B6B35DD4B" decryptionKey="2F5E2FD80991C629...3ACA674CD3B5F068" validation="SHA1" decryption="AES" />

    3. Copy and paste into the <system.web> section in the web.config file.

    If you want to follow the path I did...


    https://support.microsoft.com/en-us/kb/2915218#AppendixA
    Resolving view state message authentication code (MAC) errors Resolution 3b: Use an explicit <machineKey>
    By adding an explicit <machineKey> element to the application's Web.config file, the developer tells ASP.NET not to use the auto-generated cryptographic key. See Appendix A for instructions on how to generate a <machineKey> element.


    http://blogs.msdn.com/b/amb/archive/2012/07/31/easiest-way-to-generate-machinekey.aspx
    Easiest way to generate MachineKey - Ahmet Mithat Bostanci - 31 Jul 2012 You can search in Bing for "MachineKey generator" and use an online service. Honestly...


    http://www.blackbeltcoder.com/Resources/MachineKey.aspx

    0 讨论(0)
  • 2020-12-02 20:50

    Microsoft says to never use a key generator web site.

    Like everyone else here, I added this to my web.config.

    <System.Web>
        <machineKey decryptionKey="ABC123...SUPERLONGKEY...5432JFEI242" 
                    validationKey="XYZ234...SUPERLONGVALIDATIONKEY...FDA" 
                    validation="SHA1" />
    </system.web>
    

    However, I used IIS as my machineKey generator like so:

    1. Open IIS and select a website to get this screen:

    1. Double click the Machine Key icon to get this screen:

    1. Click the "Generate Keys" link on the right which I outlined in the pic above.

    Notes:

    • If you select the "Generate a unique key for each application" checkbox, ",IsolateApps" will be added to the end of your keys. I had to remove these to get the app to work. Obviously, they're not part of the key.
    • SHA1 was the default encryption method selected by IIS and if you change it, don't forget to change the validation property on machineKey in the web.config. However, encryption methods and algorithms evolve so please feel free to edit this post with the updated preferred Encryption method or mention it in the notes and I'll update.
    0 讨论(0)
  • 2020-12-02 20:52

    I had this problem, and for me the answer was different than the other answers to this question.

    I have an application with a lot of customers. I catch all error in the application_error in global.asax and I send myself an email with the error detail. After I published a new version of my apps, I began receiving a lot of Validation of viewstate MAC failed error message.

    After a day of searching I realized that I have a timer in my apps, that refresh an update panel every minute. So when I published a new version of my apps, and some customer have left her computer open on my website. I receive an error message every time that the timer refresh because the actual viewstate does not match with the new one. I received this message until all customers closed the website or refresh their browser to get the new version.

    I'm sorry for my English, and I know that my case is very specific, but if it can help someone to save a day, I think that it is a good thing.

    0 讨论(0)
  • 2020-12-02 20:53

    Dear All with all respict to answers up there there are case gives this error when web.config value is

    <httpCookies httpOnlyCookies="true" requireSSL="true"/>
    

    and link is http not https

    0 讨论(0)
提交回复
热议问题