Validation of viewstate MAC failed exception cause and Solution

Source: Internet
Author: User

Validation of viewstate MAC failed exception cause and Solution

This error can be found occasionally in the event log, but no effective solution can be found. After careful research and analysis, it is found that the probability of this error is very small, and multiple conditions must be met:
1. The page uses the GridView, DetailsViews, FormView, and other built-in data binding controls.
2. There is a lot of content on this page. It takes a long time to load the page when the network speed is slow.
3. If the page is not loaded, click the Postback button. This problem does not exist for url link requests in get mode.

The underlying reason is that the field names in the database tutorial are exposed in the default asp tutorial in order to avoid exposing the field names in the control such as the GridView. under the net 2.0 setting, the DataKeyNames used in the GridView is encrypted and stored in ViewState, write a hidden field <input type = "hidden" name = "_ VIEWSTATEENCRYPTED" id = "_ VIEWSTATEENCRYPTED" value = ""/> indicates that ViewState is encrypted.
Because this hidden field is at the end of the page, if the page is not fully loaded as described above, clicking the Post button will cause the backend viewstate to be deserialized on the server, this exception is thrown because the hidden domain cannot be found and the ViewState is considered invalid.

The solution is to disable ViewState encryption. The disadvantage is that the website security is reduced.
To disable ViewState encryption for the entire site or module, you only need to make the following settings in web. config:
Lt; pages enableEventValidation = "false" viewStateEncryptionMode = "Never"/>
Of course, you can only set enableEventValidation = "false" viewStateEncryptionMode = "Never" for the <@ page with this problem. In this way, the ViewState on this page is not encrypted, it does not affect the security of all pages on the entire site.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.