2011-04-13 163 views
10

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

我已经应用在计算器上的职位的解决方案,但他们并没有对我的问题制定出。

问题的细节是:

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"> 
+0

您是否正在运行网络农场? – Steven 2011-04-13 10:20:13

+1

非常奇怪,我也有类似的问题3天,现在我解决了它。 1.我已使表单认证和有SSL假 <形式defaultUrl = “〜/” loginUrl = “〜/帐户/的Login.aspx” requireSSL = “假” 超时= “2880”/> 2。但在我的httpcookies标签中,我有requireSSL = true。由于在Site.Master.cs它使用cookie来设置ViewStateUserKey,它有问题 3.因此,我得到的错误。 4.我将其修改为错误并重新启动的Web应用程序,现在它很好。 2015-02-16 08:02:15

回答

11

我问过类似的问题,前一阵子。你有see this post吗?另一件帮助我解决这个错误的方法是设置一个machineKey。看到这个Microsoft Page about the problem and setting a Machine Key

+0

如果您有网上服务器场,则还应该确保站点上的IIS站点ID在服务器之间相匹配。不知何故,这个数字被合并到ViewState的加密中。 – 2014-04-02 19:02:19

8

今天我开始有这个问题。

长话短说 - 我复制了一些表格的代码从类似的网页,然后忘记变更表单动作:

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

</form> 

上results.aspx的形式应该是:

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

</form> 

我会建议任何人检查这一点,还有任何继承值之前深入到配置和其他设置。