【问题标题】:Validation of viewstate MAC failed [duplicate]视图状态 MAC 验证失败 [重复]
【发布时间】:2011-04-13 10:11:42
【问题描述】:

可能重复:
Setting ViewStateUserKey gives me a “Validation of viewstate MAC failed” error

我已经应用了 StackOverflow 上帖子的解决方案,但它们并没有解决我的问题。

问题的具体内容是:

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.

[HttpException (0x80004005): Unable to validate data.]
   System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +10986325
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +295

[ViewStateException: Invalid viewstate. 
    Client IP: 131.155.68.60
    Port: 53999
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16
    ViewState: /wEPDwULLTIxNDQxNzQ5ODlkZDYHBedPRvEzZrTTrJvp9yAr5yfa
    Referer: http://rms.rextron.eu/login.aspx?ReturnUrl=%2fdefault.aspx
    Path: /login.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) +148
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +10959605
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +59
   System.Web.UI.HiddenFieldPageStatePersister.Load() +10959704
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +11043464
   System.Web.UI.Page.LoadAllState() +46
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11038983
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11038522
   System.Web.UI.Page.ProcessRequest() +91
   System.Web.UI.Page.ProcessRequest(HttpContext context) +240
   ASP.login_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\9ec5a6be\294c12de\App_Web_ptjxac-a.1.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

我已经尝试将它放在 web.config 中:

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

【问题讨论】:

  • 很奇怪,我也有类似的问题 3 天,现在我解决了。 1. 我启用了表单身份验证并且 ssl false 2. 但在我的 httpcookies 标签中,我有requireSSL = true。由于在 Site.Master.cs 中它使用 cookie 来设置 ViewStateUserKey,它遇到了问题 3。因此我收到了错误。 4.我把它修改为false并重新启动web应用程序,现在一切正常。

标签: asp.net viewstate


【解决方案1】:

不久前我问了一个类似的问题。你see this post了吗?帮助我解决此错误的另一件事是设置machineKey。看到这个Microsoft Page about the problem and setting a Machine Key

【讨论】:

  • 如果您有一个网络场,您还应该确保您的站点上的 IIS 站点 ID 在服务器之间匹配。不知何故,这个数字被包含在 ViewState 的加密中。
【解决方案2】:

我今天开始遇到这个问题。

长话短说 - 我从类似页面复制了一些表单代码,却忘记更改表单操作:

<form id="Form1" action="search.aspx" method="post" runat="server">

</form>

results.aspx 上的表单应该是:

<form id="Form1" action="results.aspx" method="post" runat="server">

</form>

我会建议其他人在深入研究配置和其他设置之前检查这一点以及任何继承值。

【讨论】:

    猜你喜欢
    • 2010-09-24
    • 2011-12-18
    相关资源
    最近更新 更多