C# 视图状态 MAC 验证失败。由 Web Farm 托管的应用程序,确保 <machineKey> 配置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17398954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:24:31  来源:igfitidea点击:

Validation of viewstate MAC failed.Application hosted by a Web Farm, ensure <machineKey> configuration

c#asp.net

提问by Mitesh Jain

net 4.0 frame work, I had made many website in this frame work but never get such error

net 4.0 框架工作,我在这个框架中制作了很多网站,但从未出现过这样的错误

 "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."

I think so this error is caused because of use of cookies as only in this website i had made use of cookies.

我认为这个错误是由于使用 cookie 造成的,因为我只在这个网站上使用了 cookie。

Another one thing i used to get this error very rarely almost 2twice a week

另一件事我曾经几乎每周两次出现此错误

I had read many solutions for this but very rarer for 4.0

我已经为此阅读了很多解决方案,但对于 4.0 来说非常罕见

solution readed such as putting

解决方案读取,如放置

<machineKey validationKey="6628ECBFB40F6F852AB543C23C0B83C1679C5AAE35AD72FACF5B9F4FDB70AA1F648A1D5877CE1F9D69F08BAD919BFBAC0976D9119B8F32CFB80814E4E943F8EE" decryptionKey="42F45B378301126EB4CCBA16995304263754EF116E08A81003A936CC04B7537F" validation="SHA1" decryption="AES" /> 

in web config OR Adding

在网络配置或添加

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

in webconfig

在网络配置中

But where should i add in my above web config

但是我应该在哪里添加上面的网络配置

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
<add name="Conn" connectionString="Data Source=abc; Initial Catalog=alfadesi_trikon;User ID=abc;Password=abc" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<globalization culture="en-AU" uiCulture="en-AU" />
    <compilation debug="true" targetFramework="4.0"/>
<authentication mode="Windows"/>
<customErrors mode="Off"></customErrors>    
</system.web>
</configuration>

采纳答案by vendettamit

you can add your machine key in system.web element. for e.g.

您可以在 system.web 元素中添加您的机器密钥。例如

<system.web>
<machineKey validationKey="1234567890123456789012345678901234567890AAAAAAAAAA"
 decryptionKey="123456789012345678901234567890123456789012345678"
 validation="SHA1" decryption="Auto" />
</system.web>

If you don't want to put a machinekey in the web.config for each application, you need to put it in machine level web.config for each .Net Framework version.

如果您不想在每个应用程序的 web.config 中放置 machinekey,则需要将其放置在每个 .Net Framework 版本的机器级 web.config 中。