ASP.NET: Unable to validate data

前端 未结 8 1503
野的像风
野的像风 2020-12-08 06:31

What is the cause of this exception in ASP.NET? Obviously it is a viewstate exception, but I can\'t reproduce the error on the page that is throwing the exception (a simple

8条回答
  •  一个人的身影
    2020-12-08 06:36

    This free online tool: http://aspnetresources.com/tools/machineKey generates a machineKey element under the system.web element in the web.config file. Here is an example of what it generates:

    
    

    Once you see this in your web.config, the error itself suddenly makes sense. The error you are getting says

    "ensure that configuration specifies the same validationKey and validation algorithm".

    When you look at this machineKey element, suddenly you can see what it is talking about.


    By "hard coding" this value in your web.config, the key that asp.net uses to serialize and deserialize your viewstate stays the same, no matter which server in a server farm picks it up. Your encryption becomes "portable", thus your viewstate becomes "portable".

    I'm just guessing also that maybe the very same server (not in a farm) has this problem if for any reason it "forgets" the key it had, due to a reset on any level that wipes it out. That is perhaps why you see this error after an idle period and you try to use a "stale" page.

提交回复
热议问题