简体   繁体   English

验证视图状态MAC失败。 - ASP.net

[英]Validation of viewstate MAC failed. - ASP.net

I have an C# ASP.net website hosted with www.blacknight.com. 我有一个由www.blacknight.com托管的C#ASP.net网站。

Sometimes when I login to my website I get the following error: 有时当我登录我的网站时,我收到以下错误:

在此输入图像描述

This happens in about 1 in ever 10 login attempts. 这种情况在10次登录尝试中大约发生1次。 I have contacted them and they assured me that its not hosted on a Web Farm or cluster and to check my ViewState. 我已经联系过他们,他们向我保证它不会托管在Web场或集群上并检查我的ViewState。

Does anyone know what could be wrong here? 有谁知道这里有什么不对吗? I cant reproduce it everytime so its hard to track down. 我不能每次都重现它,所以很难追查。

Please see the KB article at http://support.microsoft.com/kb/2915218 for a resolution to this issue. 有关此问题的解决方案,请参阅http://support.microsoft.com/kb/2915218上的知识库文章。 In particular, you should set an explicit <machineKey> element in Web.config. 特别是,您应该在Web.config中设置一个显式的<machineKey>元素。

Appendix A of that article tells you how to generate a <machineKey> element. 该文章的附录A告诉您如何生成<machineKey>元素。

Never set EnableViewStateMac=false. 永远不要设置EnableViewStateMac = false。 And you should never use a key that you got from a third-party generator. 而且你永远不应该使用从第三方生成器获得的密钥。 Only use one that you generated yourself. 只使用自己生成的一个。

Is it possible that IIS is recycling your application between the original page load, and the login attempt? IIS是否可能在原始页面加载和登录尝试之间回收您的应用程序? If you don't specify a <machinekey /> in the web.config, a new machine key will be generated on application start up. 如果未在web.config中指定<machinekey /> ,则将在应用程序启动时生成新的计算机密钥。 And then, when you attempt to validate the viewstate that was generated on the old machine key during post back, this exception would be thrown. 然后,当您尝试验证在回发期间在旧计算机密钥上生成的视图状态时,将抛出此异常。

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

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