视图状态 MAC 验证失败

视图状态 MAC 验证失败

我们最近将所有网站从一台服务器 (IIS6) 移至一台新服务器 (IIS7),这也涉及更改所有 DNS 记录。但是,在某些网站上,当您在某些页面上进行回发时,您会收到以下错误:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

起初我以为这可能是网站的传播问题(即它试图回发到旧服务器)。但是,DNS记录在2周前就更改了,所以肯定不是这种情况。

为什么会出现这个错误?

值得注意的是,此错误从未在旧服务器上发生过。

答案1

此问题通常是由<machineKey />服务器machine.config文件中的自动生成密钥引起的。每次应用程序重新启动时,它都会生成新密钥。这会使任何现有的加密视图状态或表单身份验证票证失效。

尝试将<machineKey /> validationKey和设置decryptionKey为固定值。有关详细信息,请参阅以下链接:

如何:在 ASP.NET 2.0 中配置 MachineKey (MSDN)

相关内容