问题
I am currently working on a Windows 2008 server, to create a web application. I am getting this error whenever I try and run my application.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I have read online that I need to add a machine key to my web config file, however I still get the error message.
Here is my current web config file
<?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>
here if the full error message
[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
Here is the code for the form
<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:
Follow the following steps and see if it helps
- Go to IIS manager--> Website--> MachineKey
- Tick Automatically generate at runtime and Generate a unique key for each application for both Validation Key and Decryption Key section.
来源:https://stackoverflow.com/questions/28946059/validation-of-viewstate-mac-failed-ensure-that-machinekey-configuration-speci