验证视图状态MAC失败。确保<machinekey>配置指定相同的validationKey和验证算法</machinekey>

时间:2015-03-09 15:42:05

标签: c# asp.net visual-studio-2010 machinekey

我目前正在使用Windows 2008服务器来创建Web应用程序。每当我尝试运行我的应用程序时,我都会收到此错误。

viewstate MAC验证失败。如果此应用程序由Web场或群集托管,请确保配置指定相同的validationKey和验证算法。无法在群集中使用AutoGenerate。

我在网上看到我需要在我的网络配置文件中添加一个机器密钥,但是我仍然收到错误消息。

这是我当前的网络配置文件

<?xml version="1.0"?>


<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <machineKey validationKey='00D057688A87D8BF33008D0A3DBB5790AF8A113942A216DAC73F179B21A92A529215B38D757F17B25F08DF2F0BFD11743C57716D4954BBF4E8F7180D60ED6ECE' 
                    decryptionKey='FDB6365E13BE1A8694CF0684BE1AA3580972C143A9B53420' validation='SHA1'/>
        <authorization>
            <allow users ="*"/>
        </authorization>
    </system.web>
</configuration>

此处如果有完整的错误消息

[ViewStateException: Invalid viewstate. 
    Client IP: 127.0.0.1
    Port: 
    Referer: http://localhost:51339/Registration/ResetPassword.aspx
    Path: /Registration/ChangePassword.aspx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
    ViewState: /wEPDwUKLTQ4NDk4NTQ3OGRkDZ/JArXLAjjsKSeaiULV8d+8NOM=]

[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) +198
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +432
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
   System.Web.UI.HiddenFieldPageStatePersister.Load() +248
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
   System.Web.UI.Page.LoadAllState() +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
   System.Web.UI.Page.ProcessRequest() +72
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +58
   ASP.registration_changepassword_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\31036172\2ef1977\App_Web_akxob5yx.3.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

以下是表单

的代码
<form id="Form1" runat="server" action="ChangePassword.aspx" method="get"> 
   <div style="font-family:Arial">
    <table style="border: 1px solid black; width:300px">
        <tr>
            <td colspan="2">
                <b>Reset my password</b>
            </td>
        </tr>
        <tr>
            <td>
                User Name
            </td>    
            <td>

                <asp:TextBox ID="txtUserName" Width="150px" runat="server" 
                ontextchanged="txtUserName_TextChanged">
                </asp:TextBox>


            </td>    
        </tr>
        <tr>
            <td>

            </td>    
            <td>

                <asp:Button ID="btnResetPassword" runat="server" 
                Width="150px" Text="Reset Password" onclick="btnResetPassword_Click" />
            </td>    
        </tr>
        <tr>
            <td colspan="2">
                <asp:Label ID="lblMessage" runat="server"></asp:Label>
            </td>    
        </tr>
    </table>
</div>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

按照以下步骤查看是否有帮助

  1. 转到IIS管理器 - &gt;网站 - &GT;的machineKey
  2. 勾选在运行时自动生成并为验证密钥和解密密钥部分的每个应用程序生成唯一密钥。