Asp.net Validation of viewstate MAC failed

前端 未结 16 1595
猫巷女王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:56

    my problem was this piece of javascript code

    $('input').each(function(ele, indx){
        this.value = this.value.toUpperCase();
    });
    

    Turns it was messing with viewstate hidden field so I changed it to below code and it worked

    $('input:visible').each(function(ele, indx){
        this.value = this.value.toUpperCase();
    });
    
    0 讨论(0)
  • 2020-12-02 20:57

    This solution worked for me in ASP.NET 4.5 using a Web Forms site.

    1. Use the following site to generate a Machine Key: http://www.blackbeltcoder.com/Resources/MachineKey.aspx
    2. Copy Full Machine Key Code.
    3. Go To your Web.Config File.
    4. Paste the Machine Key in the following code section:
        <configuration>
          <system.web>
            <machineKey ... />
          </system.web>
        </configuration> 
    

    You should not see the viewstate Mac failed error anymore. Each website in the same app pool should have a separate machine key otherwise this error will continue.

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

    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.

    Answer :

    <machineKey  decryptionKey="2CC8E5C3B1812451A707FBAAAEAC9052E05AE1B858993660" validation="HMACSHA256" decryption="AES" validationKey="CB8860CE588A62A2CF9B0B2F48D2C8C31A6A40F0517268CEBCA431A3177B08FC53D818B82DEDCF015A71A0C4B817EA8FDCA2B3BDD091D89F2EDDFB3C06C0CB32" />

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

    There are another scenario which was happening for my customers. This was happening normally in certain time because of shift changes and users needed to login with different user. Here is a scenario which Anti forgery system protects system by generation this error:

    1- Once close/open your browser. 2- Go to your website and login with "User A" 3- Open new Tab in browser and enter the same address site. (You can see your site Home page without any authentication) 4- Logout from your site and Login with another User(User B) in second tab. 5- Now go back to the first Tab which you logged in by "User A". You can still see the page but any action in this tab will make the error. Because your cookie is already updated by "User B" and you are trying to send a request by an invalid user. (User A)

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题