简体   繁体   English

验证视图状态MAC失败

[英]Validation of viewstate MAC failed

Running the ASP.NET webforms run the application works fine. 运行ASP.NET Web窗体,运行应用程序运行正常。 When the application is idle for 4 to 5 minutes, it is giving this error: 当应用程序空闲4到5分钟时,会出现此错误:

Validation of viewstate MAC failed. 验证视图状态MAC失败。 If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. 如果此应用程序由Web场或群集托管,请确保配置指定相同的validationKey和验证算法。 AutoGenerate cannot be used in a cluster. 自动生成不能在群集中使用。

How can this be solved? 如何解决呢?

This free online tool: http://aspnetresources.com/tools/machineKey generates a machineKey element under the system.web element in the web.config file. 这个免费的在线工具: http ://aspnetresources.com/tools/machineKey在web.config文件中的system.web元素下生成一个machineKey元素。 Here is an example of what it generates: 这是它生成的示例:

<machineKey validationKey="1619AB2FDEE6B943AD5D31DD68B7EBDAB32682A5891481D9403A6A55C4F91A340131CB4F4AD26A686DF5911A6C05CAC89307663656B62BE304EA66605156E9B5" decryptionKey="C9D165260E6A697B2993D45E05BD64386445DE01031B790A60F229F6A2656ECF" validation="SHA1" decryption="AES" />

Once you see this in your web.config, the error itself suddenly makes sense. 一旦在web.config中看到此错误,错误本身就突然变得有意义。 The error you are getting says 你得到的错误说

"ensure that configuration specifies the same validationKey and validation algorithm". “确保配置指定相同的validationKey和验证算法”。

When you look at this machineKey element, suddenly you can see what it is talking about. 当您查看此machineKey元素时,突然您可以看到它在说什么。

Modifying the pages element under the system.web element may not be necessary with this in place. 在此情况下,可能不需要修改system.web元素下的pages元素。 This avoids the security problems associated with those attributes. 这避免了与那些属性相关的安全性问题。


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. 通过在您的web.config中“硬编码”此值,无论服务器场中的哪台服务器将其拾取,asp.net用于序列化和反序列化您的视图状态的键都保持不变。 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. 这也许就是为什么您在空闲时间后看到此错误并尝试使用“陈旧”页面的原因。

This isn't your problem but it might help someone else. 这不是您的问题,但可能会对其他人有所帮助。 Make sure you are posting back to the same page. 确保您要发回到同一页面。 Check the action on your form tag and look at the URL your browser is requesting using Firefox Live HTTP Headers. 检查您的表单标签上的操作,并查看您的浏览器使用Firefox Live HTTP标头请求的URL。

I ran into this because I was posting back to a page with the same name but a different path. 我之所以遇到这种情况,是因为我发回到了具有相同名称但路径不同的页面。

Modify your web.config with this element: 使用以下元素修改您的web.config:

<pages validateRequest="false" 
       enableEventValidation="false" 
       viewStateEncryptionMode ="Never" />

Any more info required, refer to the ASP.NET Forums topic 需要任何其他信息,请参考ASP.NET论坛主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM