Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configurati
I am using VS tester edition 2008. I was trying to record session with Fiddler as i have some pop up windows that i want to recorder and VS doesn't allow to do that.
So, i recorded the Fiddler web test, then covert it into VS web test and then generated a coded web test, as I had to parameterize it. So, let's say I was playing back coded web test against site name http://servername/SiteName1. What i did after that i changed all the URLs to point to the other site http://servername/SiteName2.
On one of the requests i got this error "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. ".
My viewstate looks like this:Code Snippet
request2Body.BodyString ="-----------------------------7d810a183027e\r\nContent-Disposition: form-data; name=" + "\"__EVENTTARGET\"\r\n\r\nlbLogIn\r\n-----------------------------7d810a183027e\r\nContent-" + "Disposition: form-data; name=\"__EVENTARGUMENT\"\r\n\r\n\r\n----------------------------" + "-7d810a183027e\r\nContent-Disposition: form-data; name=\"__VIEWSTATE\"\r\n\r\n/wEPDwUJNT" + "IyMzA3MzA1DxYCHgJ0cAUMRGVmYXVsdC5hc3B4FgJmD2QWCgIBDw8WAh4EVGV4dAUGTG9nIEluZGQCAw" + "9kFgoCAQ8PFgIfAQUGRS1NYWlsZGQCBQ8PFgIfAQUIUGFzc3dvcmRkZAIJDw8WAh8BBQZMb2cgSW4WAh" + "4Hb25DbGljawUWamF2YXNjcmlwdDogU2F2ZUZvcm0oKWQCCw8PFgQeC05hdmlnYXRlVXJsBU1odHRwOi" + "8vSFFQLUFTLVJUUzAxL1BvcnRhbFYyMzFTUDFQZXJmb3JtYW5jZS9Nb2R1bGVzV0kvTmV3VXNlckVucm" + "9sbG1lbnQuYXNweB4HVmlzaWJsZWhkZAINDw8WAh8BBQ1TZW5kIFBhc3N3b3JkFgIfAgXAAWphdmFzY3" + "JpcHQ6IHJldHVybiBjb25maXJtKCdUaGlzIHdpbGwgcmVzZXQgeW91ciBwYXNzd29yZCB0byBhIHJhbm" + "RvbSBzdHJpbmcgYW5kIGVtYWlsIGl0IHRvIHRoZSBzcGVjaWZpZWQgZW1haWwgYWNjb3VudC4gWW91IH" + "dpbGwgbm90IGJlIGFibGUgdG8gbG9nIGluIHdpdGggeW91ciBjdXJyZW50IHBhc3N3b3JkIGFueSBtb3" + "JlLicpO2QCBQ9kFhACAQ8PFgIfAQUPQ2hhbmdlIFBhc3N3b3JkZGQCAw8PFgIfAQUIUGFzc3dvcmRkZA" + "IHDw8WAh4MRXJyb3JNZXNzYWdlBRxZb3UgbXVzdCBwcm92aWRlIGEgcGFzc3dvcmQhZGQCCQ8PFgIfBQ" + "UnVGhlIHBhc3N3b3JkIG11c3QgYmUgNiBjaGFyYWN0ZXJzIGxvbmchZGQCCw8PFgIfBQUzVGhlIHBhc3" + "N3b3JkIG11c3QgY29udGFpbiBib3RoIGxldHRlcnMgYW5kIG51bWJlcnMhZGQCDQ8PFgIfAQUQQ29uZm" + "lybSBQYXNzd29yZGRkAhEPDxYCHwUFG1RoZSBwYXNzd29yZHMgZG8gbm90IG1hdGNoIWRkAhMPDxYCHw" + "EFBlN1Ym1pdGRkAgcPDxYCHwUFHlBsZWFzZSBlbnRlciBhbiBlbWFpbCBhZGRyZXNzLmRkAgkPDxYCHw" + "FlZGRkzVeoFzOoy9ocI8l5Ov2swUMkuXI=\r\n-----------------------------7d810a183027e\r\n" + "Content-Disposition: form-data; name=\"tbUserEmail\"\r\n\r\email@example.com\r\n--" + "---------------------------7d810a183027e\r\nContent-Disposition: form-data; name=\"" + "tbUserPassword\"\r\n\r\npassword1\r\n-----------------------------7d810a183027e\r\nConten" + "t-Disposition: form-data; name=\"__EVENTVALIDATION\"\r\n\r\n/wEWBQKL04/2BwKrn/j/BgKyr5" + "hiAtHLwdgCAvfxgIAK6rXt0u7xcm6ZogTyCg2u8hYksXM=\r\n-----------------------------7d8" + "10a183027e--\r\n";
What i've already tried was: put unique machine key into the machine.config file. Change web.config file with EnableViewState="false". Decoded Viewstate and still can't find what is the issue about.
I assume that it doesn't like that the name of the site is different, as it still can be run perfectly on the first site that it had been recorded against.
Does anyone know what else can be wrong? And where else can i check?
Thank youSunday, March 02, 2008 9:48 PM
Tuesday, March 04, 2008 8:36 PM
First, are there specific requests that the recorder in VS 2008 does not record. PLease let me know. There were certain popups that the vs2005 recorder would not capture, but I am not aware of what the vs 2008 will not capture.
Second, you have a hard coded view state value. This is going to be your problem. When you recorded with fiddler, did you select the options to correlate viewstate? If that dod not work, you may need to do this manually. This value should be extracted from the previous request and bound into this request.Monday, March 03, 2008 1:39 PMModerator
I've been having the issue with our application with both VS 2005 and VS 2008 (even VS 2008 doesn't record pop up windows and it doesn't record file uploading) so i decided to use Fiddler to avoid all this issues.
I have a couple of questions to you.
1. How to correlate viewstate in Fiddler? I was trying to figure out how to do that but couldn't find that in the Menu options.
2. I know that Viewstate is hard coded and looks like a string. But in the string there are some more values that i might want to use to parameterize. Like if i am creating a new organization I want to give a new name each time when i am adding it. If I will extract this whole viewstate how would i be able to do parameterizing? Or is it possible to break up the string to pieces? And extract only Viewstate part of it?
Looking forward to hear from you
SashaMonday, March 03, 2008 6:20 PM
Check out this post for fiddler info: http://blogs.msdn.com/slumley/pages/enhanced-web-test-support-in-fiddler.aspxTuesday, March 04, 2008 1:13 AMModerator
Thank you for respond.
I looked at the link and it seems that i am using the right version of Fidller and that it correlates the Viewstate. I just hadn't noticed that untill you pointed me to that. BUT the Viewstate parameters don't look the same as in the post. What i really see in my web test (i am not talking about the coded webb test) is: Query String Paramets, Headers and BodyString which i can't modify. All that i can do with it is to open it in the properties and open a little pop up window that allows me only to review the content of it. I can't send the screen shot of it so i am not sure if you clear of what i am talking about.
Slumley, do you have any ideas why my VIEWSTATE doesn't look like as it should be?
Also, i still have those questions from the previos post. Could you please answer them as well?
Thank you for your responses!
SashaTuesday, March 04, 2008 1:36 AM
Tuesday, March 04, 2008 8:36 PM
This is a visual studio bug. There is a bug that we are not recording some file upload requests. That appears to be what you are hitting. The fix will correctly reocrd the requests and handle the correlation of fields such as view state. I am not 100% sure that is what you are hitting, but it seems likely from what you have described.
Also, you can still try to get this to worj with fiddler, but then you will need to do all the correlation since fiddler is not correlating the fields.Tuesday, March 04, 2008 9:52 PMModerator
I am totally confused. I thought that the bug was about the Viewstate. That the viewstate after being converted from Fiddler and correlate the Viewstate in it doesn't appear right in VS. It doesn't appear like the hidden field in the web test tree, but it does appear as a body string that can't be editable. As I hitt the error not only in the file uploading case. I have this error for any request that has Viewstate in it that comes from Fiddler and where the correlation were applied from Fiddler side.
If Fiddler can't do the correlation properly for our app what is the way of doing that?
Thank youTuesday, March 04, 2008 10:04 PM
That is a problem with the way fiddler is creating the web test. The fix will have the vs 2008 recorder correctly record and correlate view state. The viewstate will not be added as a string body with 2008. The way of doing it is with 2008.
Also, you could get fiddler to correlate correctly, but you would need to write a fiddler plugin to get it to work. You can change how fiddler writes out the web test. Here is a blog post on fiddler plugins:Friday, March 07, 2008 2:43 PMModerator
In our company we are using VSTS 2005 and have faced the above problem with Viewstate as you do.
The solution we have found right now is this:
We have nearly 35-40 scripts for our performance test. Each time when we a new application build to test, we record the scenario of all the scripts using Fiddler and compare the viewstate for all the POST request with the POST request in the scripts recorded for the previous script, if there is a change then we replace the old viewstate with the new one. And it works perfectly without any errors.
I know it is hard part but we have no other choice.
But lately we have found permanent solution by using Extraction rules in VSTS. Currently we are doing some R&D on it and will soon post the updates on it.
Note: We are using coded webtest.
I hope this helps.
YashSunday, March 09, 2008 3:15 PM
The hotfix for the problem described in this thread is released. Note however the KB has not been published. Nevertheless, you can get the fix by creating a case or incident with Microsoft. Contact Microsoft at (800) 936-5800 opt 3. Request Hotfix 946673. Note in the earlier thread I referenced KB 361949, which is incorrect. The correct Hotfix number is 946673. I will follow up once again when the KB has been published.Tuesday, April 01, 2008 8:07 PM
This solved my Problem
This is caused by the application pool setting on the performance tab, web garden. Make sure its set to 1, otherwise it will have x app pools who all have different viewstate encryption keys and so it may work if you get the same app pool but the next trip to the server it could bomb if it gets the other app poolWednesday, April 16, 2008 3:25 PM
Can any one advise me i am also geeting same error, if a user leaves a browser session
idle for a while (more than 10 minutes?). .net 2.0 vs 2005
Server Error in '/' Application.
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.
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:
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.
[HttpException (0x80004005): Unable to validate data.] System.Web.Configuration.MachineKeySection.GetDecodedData(Byte buf, Byte modifier, Int32 start, Int32 length, Int32& dataLength) +294 System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +203 [ViewStateException: Invalid viewstate. Client IP: 22.214.171.124 Port: 53630 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Alexa Toolbar) ViewState: /wEPDwUKMTc4OTA5NTcyMg9kFgICAQ9kFgJmDxYCHgdWaXNpYmxlaGRk0vguldqCcKjUNaWurCQfHOUnfXE= Referer: http://xxxxxxxxxxx.co.uk/contact.aspx Path: /contact.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) +267 System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +282 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() +198 System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +83 System.Web.UI.Page.LoadAllState() +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7350 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213 System.Web.UI.Page.ProcessRequest() +86 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18 System.Web.UI.Page.ProcessRequest(HttpContext context) +49 ASP.contact_aspx.ProcessRequest(HttpContext context) +29 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +358 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433Tuesday, August 19, 2008 1:29 PM
To be sure I understand you right, is this happening outside of a webtest, to a human user?
If so it's really outside of the scope of this forum which deals with automated web/loadtests created with visual studio.
I'd advise you to check the settings on the server(s?) for how viewstate is handled. The exception details of the error pretty much are pointing you in the direction you need to go to solve an error like this in a real-world environment.
e.g. if this happens inside automation, it could be an issue with the site, but is more often a failure to properly handle VIEWSTATE parameters inside the test. (see the above messages in this thread for more info on that)
If this happens to a live user then it is typically indicative of a problem with how VIEWSTATE generation and handling is configured on the server(s) for the website. (seek advice in a forum for IIS, ASP.NET, etc)Tuesday, August 19, 2008 8:36 PM
I have the exact same issue in the application I am currently testing.
We have recorded a webtest using fiddler, including correlation and all the other things discussed in this thread. As the OP, we too are able to run the webtest just fine when we import it staright away, but as soon as we parameterize the post id's, we get the "MAC failed" error.
I have just installed the VS 2008 SP1, which according to the Service Pack description, should include the Hotfix 946673 mentioned in this thread.
However, installing the service pack did not fix this issue for me. I noticed however when I go to the details TAB on the request that has the error, that it fails on extracting the form field __EVENTVALIDATION, explaining that it couldn't find the field.
I found another thread (http://social.msdn.microsoft.com/Forums/en-US/vstswebtest/thread/ce7b3de6-5033-4bd9-8256-5df077c46914/) on this forum where someone suggsted that this error occured, due to the page not loading before the next request is being launched. But it is never fully concluded whether this is a plausible soultion to this error message. I have tried increasing the think time, but I might be doing something wrong, as it doesn't seem like the thinktime is taken into account despite the fact that is has been increased to almost 60 seconds.
Please advise if you have an answer to this.
Wednesday, November 12, 2008 9:40 AM
Would you please explain me how did you solve the problem of this Viewstate mac failed.
Can you please expain me step by step how to do it.
I have client who is really annoyed by this error and wants me to do something.
I am new bee.
I have page connected with database and this page sometime stay idle for more than 20 min and when my client trys to add some data or try to upload something it give me this error.
I m so surpirsed when i read that you soleve the problem but i cant understand how did you do that.
Thanks for your time.
JAY PATELThursday, February 05, 2009 8:57 PM
can you provide a very little example solution please so people like me can understanad that how to do it because i am not that professional ,,,,i will be so appericiate your help and time you give to me.
Thursday, February 05, 2009 9:01 PM
- Proposed as answer by Ranjancse Monday, April 27, 2009 5:07 AM
If you are setting Session State to say StateServer then you need to add machine key configuration key in Web.config else you will run out with this 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."
Here;s sample machine key config
You need to add this to encrypt the ViewState information is a WebFarm
Please read the above reference from MSDN you will come to know clearly
Monday, April 27, 2009 5:12 AM
- Edited by Ranjancse Monday, April 27, 2009 5:14 AM
Just put this code in the Web.Config between the <system.web> tags, this tag is:
<pages enableViewStateMac="false" />
the result will be:
<pages enableViewStateMac="false" />
Can you replay if it worked with you? Vote for it if it was helpful
It Was my big problem ... I just worked NowSaturday, June 05, 2010 2:33 PM
The reason for this error is validation of Viewstate failing because of different value of key for encryption/decryption across different server on farm. Below link provide good explanation of this error and possible resolution for the same.
Wednesday, September 22, 2010 6:46 PM
Duane LawrenceTuesday, May 08, 2012 8:30 PM
hi, can someone provide the details of the fix on this issue? We are also encountering the same issue for our web performance test.
I am using VSTS 2010 (Ultimate). The webtest recording seems fine, but it is having error during the playback. Our scenario is we have a page that calls a pop up screen to upload file attachment and indicate the document type-dropdown. Upon clicking upload, the details (filename, file size and document type) of the attachment is displayed in the main page. The subsequent errors may be related to this.Monday, June 25, 2012 4:07 AM