Click here to Skip to main content
14,237,525 members
Rate this:
Please Sign up or sign in to vote.
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.


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" %>


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

       <compilation debug="true"/>

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:
    Port: 3521
    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
Thomas Daniels 31-Oct-12 6:21am
What's the code you're using?
Ankur Ramanuj 31-Oct-12 8:15am
i have used 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?
Ankur Ramanuj 31-Oct-12 9:25am
My code is like: Page Name(Default.aspx.cs)

DataRow drLogin = null;
BAL.bal_tbl_UserLogin balUserlogin = new BAL.bal_tbl_UserLogin();
OAL.obj_tbl_UserLogin oalUserlogin = new OAL.obj_tbl_UserLogin();
oalUserlogin.UserName = Convert.ToString(txtUserName.Text);
oalUserlogin.UserPassword = new AllSecurity().base64Encode(txtPassword.Text);
if (balUserlogin.Select_WithAnd(oalUserlogin))
if (balUserlogin.m_RowAffected > 0)
drLogin = balUserlogin.m_Ds.Tables[0].Rows[0];
if (Convert.ToBoolean(drLogin["LoginStatus"]) == true)
string AppSessionID = "l%34$Cae8D";
if (AppSessionID != "")
Session["SessionID"] = Session.SessionID;
HttpCookie UserCookies = new HttpCookie(Convert.ToString(AppSessionID));
UserCookies.Expires = DateTime.Now.AddDays(1);
UserCookies["UID"] = Convert.ToString(drLogin["UserName"]);
UserCookies["UPP"] = Convert.ToString(txtPassword.Text);
UserCookies["EID"] = Convert.ToString(drLogin["EmployeeID"]);
UserCookies["Ename"] = Convert.ToString(drLogin["First_Name"]) + " " + Convert.ToString(drLogin["Last_Name"]);
UserCookies["Utype"] = Convert.ToString(drLogin["OfficeType"]);
UserCookies["Role"] = Convert.ToString(drLogin["RoleID"]);
UserCookies = new HttpCookieEncryption().encrypt(UserCookies);
string strTicket = Convert.ToString(Session.SessionID);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(strTicket, false, 200);
string encTicket = FormsAuthentication.Encrypt(ticket);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

lblErrorMSg.Text = "Your login access has been failed, Contact your administrator.";
lblErrorMSg.Text = "User login failed. Invalid Username or Password.";
lblErrorMSg.Text = "User login failed. Invalid Username or Password." + balUserlogin.m_Error.ToString();
catch (Exception ex) { lblErrorMSg.Text = ex.Message.ToString(); }
Thomas Daniels 31-Oct-12 10:46am
I mean the ASP.NET tags used in your .aspx file.
So, the HTML tags of your form. Is it possible that the action attribute of the form contains the name of another web form then the web page with your form?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
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 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100