Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

XML
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[ViewStateException: Invalid viewstate.
    Client IP: 122.169.12.9
    Port: 3521
    Referer: http://casoftware.in/
    Path: /Default.aspx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Firefox/17.0
    ViewState: /wEPDwUKMTc3OTk1NzcyMA9kFgICAQ9kFgICCQ8PFgIeBFRleHQFMFVzZXIgbG9naW4gZmFpbGVkLiBJbnZhbGlkIFVzZXJuYW1lIG9yIFBhc3N3b3JkLmRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQtpbWdidG5Mb2dpbjLGD7mxikYAn7Ip9Houbb+AwsEyU6sRJhCZwY/cnqvz]

[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) +235
   System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +274
   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() +241
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
   System.Web.UI.Page.ProcessRequest() +78
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.default_aspx.ProcessRequest(HttpContext context) +4
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Posted
Comments
Thomas Daniels 31-Oct-12 6:21am    
What's the code you're using?
Ankur Ramanuj 31-Oct-12 8:15am    
i have used c#.net framework 4.0
Thomas Daniels 31-Oct-12 8:25am    
No, I ask the ASP.NET code. Not the programming language.
Ankur Ramanuj 31-Oct-12 8:57am    
ok sorry, in my code i have just create a cookie for store value like username,CompanyID,UserID..nothing else
Thomas Daniels 31-Oct-12 8:59am    
And in your ASP.NET page?

1 solution

When I see the error, I can guess that the action of the form is another page then Default.aspx. If the action is Default.aspx, the same page as the page with the button, there's no problem. If you compile the ASP.NET pages, and if you see the HTML code, then you can see that in the same form as the form with the button there're hidden values. One of the hidden values is the MAC Viewstate. But the Viewstate is for Default.aspx. If you click on the button, and if you go to another page, the Viewstate is incorrect for the specified page. The Viewstate is only correct for Default.aspx.

To solve it, you can remove the action attribute from the form and redirect to another page on button click.
 
Share this answer
 
v2
Comments
Ankur Ramanuj 2-Nov-12 2:33am    
when i have click on login button than i'm redirect on Home.aspx form but i'm click on this button thn this error is occured or sometimes i have refressed this page than it's work fine ...so i can't understand what can i do?
Thomas Daniels 2-Nov-12 4:47am    
Remove the action attribute from your form. Add a OnClick event handler to your button, and on button click, redirect to Home.aspx
Ankur Ramanuj 3-Nov-12 1:46am    
i have done same in my code..all above code is written in button click event...
Deva Kumar D. 17-Nov-12 1:57am    
When I see the above solution, It seems to be ok. But in my web site I have no action attribute in my master page or ordinary .aspx pages. But while running I could see the action attribute with the empty string by right clicking on the web page and selecting the "view page source option".

How can I remove the action attribute when I don't have it in my page??

I am sorry if my question is very poor...
Thomas Daniels 17-Nov-12 5:47am    
Good question. Then, you can't. It's possible that there's a little problem in the configuration page. Can you post the content of your configuration file, please?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900