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.