C# System.Web.HttpException:在ASP.NET中验证viewstate MAC失败

C# System.Web.HttpException:在ASP.NET中验证viewstate MAC失败,c#,asp.net,macos,C#,Asp.net,Macos,我在asp.net中开发了一个应用程序。现在我正在尝试将其托管在另一台服务器中。从该服务器运行此应用程序时,出现以下错误: 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 alg

我在asp.net中开发了一个应用程序。现在我正在尝试将其托管在另一台服务器中。从该服务器运行此应用程序时,出现以下错误:

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. 
查看状态MAC的验证失败。如果此应用程序由Web场或群集托管,请确保配置指定了相同的validationKey和验证算法。无法在群集中使用自动生成。 堆栈跟踪如下所示:

[ViewStateException: Invalid viewstate. 
    Client IP: 10.11.201.84
    Port: 62640
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/8.0; .NET4.0C; .NET4.0E; InfoPath.3; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; .NET CLR 1.1.4322)
    ViewState: /wEPDwUKLTE4MDU5MzAwNg9kFgICAw8WAh4GYWN0aW9uBWpmYW12ZXJpZnlIb21lLmFzcHg/bmFtZT05ODkmYXBwdXNlcj0nUkFOQTAwMScmYWlsb2dpZD0nMScmZGVwYW1vdW50PSZzZXNzaWQ9JzI4OTAyMzQzMDkzMTQ1ICcmY3VzdG5vPSc5ODknZGQ43r63dbDPk+BB/tFxs4xJkThUIQ==
    Referer: http://10.11.201.170/finger/startverifyHome.aspx?name=989&ailogid='1'&appuser='RANA001'&depamount=&custno='989'&sessid='28902343093145%20'
    Path: /finger/famverifyHome.aspx]

[HttpException (0x80004005): 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.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +106
   System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +237
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +207
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +105
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
   System.Web.UI.Page.ProcessRequest() +80
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.famverifyhome_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\finger\7c8a0dc9\bf1de8ca\App_Web_yhgsi6y0.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
[viewstate异常:无效的viewstate。
客户IP:10.11.201.84
港口:62640
用户代理:Mozilla/4.0(兼容;MSIE 7.0;Windows NT 10.0;WOW64;Trident/8.0;.NET4.0C;.NET4.0E;InfoPath.3;.NET CLR 2.0.50727;.NET CLR 3.0.30729;.NET CLR 3.5.30729;.NET CLR 1.4322)
视图状态:/wEPDwUKLTE4MDU5MzAwNg9kFgICAw8WAh4GYWN0aW9uBWpmYW12ZXJpZnlIb21lLmFzcHg/BMFTZT05ODKMYXBWDXNLCJ0NUKFOQTAWMSCMYWLSB2DPZD0NMSCMZGVWYW1VDW50PSZZZXNZAWQ9JZI4ZMDK1CCM3VZDG5VPSC5ODKNZGQ43R63DBDPK+TFXS4XJKTUIQ==
推荐人:http://10.11.201.170/finger/startverifyHome.aspx?name=989&ailogid=“1”&appuser='RANA001'&depamount='989'和sessiond='28902343093145%20'
路径:/finger/famverifyHome.aspx]
[HttpException(0x80004005):viewstate MAC验证失败。如果此应用程序由Web场或群集托管,请确保配置指定了相同的validationKey和验证算法。不能在群集中使用AutoGenerate。]
System.Web.UI.ViewStateException.ThrowError(内部异常、字符串persistedState、字符串errorPageMessage、布尔macValidationError)+106
System.Web.UI.ViewStateException.ThrowMacValidationError(内部异常,字符串persistedState)+14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)+237
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)+4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter格式化程序,String serializedState)+37
System.Web.UI.HiddenFieldPageStatePersister.Load()+207
System.Web.UI.Page.LoadPageStateFromPersistenceMedium()+105
System.Web.UI.Page.LoadAllState()+43
System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+6785
System.Web.UI.Page.ProcessRequest(布尔includeStagesBeforeAsyncPoint,布尔IncludeStagesSafterAsyncPoint)+242
System.Web.UI.Page.ProcessRequest()+80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext上下文)+21
System.Web.UI.Page.ProcessRequest(HttpContext上下文)+49
c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\finger\7c8a0dc9\bf1de8ca\App\u Web\u yhgsi6y0.0.cs:0中的ASP.famverifyhome\u aspx.ProcessRequest(HttpContext上下文)
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+181
System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,布尔值&同步完成)+75

  • 我已打开IIS并选择我的网站以获取此屏幕:
  • 我已双击机器钥匙图标以获得此屏幕:
  • 然后,当我生成密钥时,在我的web.config文件中输入以下内容

    <machineKey decryption="AES" decryptionKey="A9392EC7910C......CF5F8D31AD08B1E68AAEA94BEB939C" validation="SHA1" validationKey="2763A48574235661A1......21F289237DE25A14EF0EF97BCFE1A78B2F0B504E5F9021422E737F11D26CD5DD0D311F17AD93BC5E486C8907159C6252FE8C70DE" />
    
    
    

    但我的问题仍然没有解决。我怎样才能解决这个问题?请帮帮我

    如果您使用的是ASP.NET 4.5,请按照以下步骤操作:

  • 使用以下站点生成机器密钥:
  • 复制完整的机器密钥代码
  • 转到Web.Config文件
  • 将机器钥匙粘贴到以下代码部分:

  • Edit:enableViewStateMac=False不推荐使用(参考)


    您不应该再看到viewstate Mac failed错误。同一应用程序池中的每个网站都应该有一个单独的机器密钥,否则此错误将继续。

    这也可能是因为:

    <httpCookies requireSSL="true" />
    
    
    

    而且您没有使用HTTPs。

    切勿使用公共资源生成机器密钥:请参阅附录a“附录a:如何生成元素”确认。在我的本地开发环境中,除非您在项目属性中专门设置了https(在Visual Studio中按F5或Ctrl F5时使用http是常见的/默认的),否则我会遇到错误。当我用http设置
    时,我得到了错误。当我将项目属性更改为使用https时,没有出现错误。当我用http更改
    requireSSL=“false”
    时,错误没有出现。