locked
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configurati

    Question

  • Hi,

     

    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\nadmin@sarboxportal.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 you

    Sunday, March 02, 2008 9:48 PM

Answers

  •  

    We are currently working on this fix and it should be ready in the next week or so. To get the fix you will have to contact Microsoft at 800 936-5800 (select option 3) to open a case and request Fix number KB 361949. Note since this is a hotfix you will not be charged or decremented an incident. However, you are still required to open a case. Again the fix is not available now, but I will post again once the fix become ready.
    Tuesday, March 04, 2008 8:36 PM

All replies

  • 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 PM
  • Hi Slumley,

     

    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?

     

    Thank you

    Looking forward to hear from you

    Sasha

    Monday, March 03, 2008 6:20 PM
  • Tuesday, March 04, 2008 1:13 AM
  • Hi Slumley,

     

    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!

     

    Sasha

     

    Tuesday, March 04, 2008 1:36 AM
  • I think you are hitting a bug for which we are putting out a qfe for. I will have someone respond back with info on how to get it.

     

    Tuesday, March 04, 2008 6:03 PM
  •  

    We are currently working on this fix and it should be ready in the next week or so. To get the fix you will have to contact Microsoft at 800 936-5800 (select option 3) to open a case and request Fix number KB 361949. Note since this is a hotfix you will not be charged or decremented an incident. However, you are still required to open a case. Again the fix is not available now, but I will post again once the fix become ready.
    Tuesday, March 04, 2008 8:36 PM
  • Thank you for following up Jonny. I will do what you said.

    Could you please aslo give me some information about the bug? And aproximate time when the fix will be done?

    And is this a VS bug or Fiddler one? 

     

    Thank you

     

    Tuesday, March 04, 2008 9:04 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 PM
  • Slumley,

     

    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 you

     

    Tuesday, 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:

    http://blogs.msdn.com/slumley/pages/writing-fiddler-web-test-plugins.aspx

    http://blogs.msdn.com/slumley/pages/another-fiddler-plugin-example.aspx

     

    Friday, March 07, 2008 2:43 PM
  • Hi,

    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.

    Regards,
    Yash
    Sunday, 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 pool

    Wednesday, April 16, 2008 3:25 PM
  • Hi,

     

    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.

    Source Error:

    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:

    [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: 78.105.93.161
    	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.1433

    Tuesday, 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.

    Best regards

    Dan Tejsner
    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.

    Please help.
    Thanks for your time.
    JAY PATEL
    Thursday, 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.
    Thanks
    Jay
    JAY PATEL
    • Proposed as answer by Ranjancse Monday, April 27, 2009 5:07 AM
    Thursday, February 05, 2009 9:01 PM
  • Hi,

    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
    <machineKey
          validationKey="9B648362BE0A4C3FEDD4D9C97F148CA71497C5128BF543DDB37D70AEFBA2F16D184A900AC1C16331F5E95708BAD6A67286B74CEBBE4ACDEA58B787AF1BD7BFE4"
    decryptionKey="86D46880FD9C2F391D9176A24EF22A16560AD69B7AE37146"
    validation="SHA1" />

    You need to add this to encrypt the ViewState information is a WebFarm

    Reference: http://msdn.microsoft.com/en-us/library/ms998288.aspx
    Please read the above reference from MSDN you will come to know clearly
    • Edited by Ranjancse Monday, April 27, 2009 5:14 AM
    Monday, April 27, 2009 5:12 AM
  • Just put this code in the Web.Config  between the <system.web>  tags, this tag is:


          <pages enableViewStateMac="false" /> 

     

     

    -------------

     

    the result will be:

    <system.web>

         .

         .

         .

         <pages enableViewStateMac="false" /> 

    <system.web>

     

    ------------

     

    Can you replay if it worked with you? Vote for it if it was helpful

     

    It Was my big problem ... I just worked Now

     

    Saturday, 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
  •  

    <system.web>
    
       .
    
       .
    
       .
    
       <pages enableViewStateMac="false" /> 
    
    <system.web>
    
    

     

    Thanks. This has helped me too.

    Tuesday, October 19, 2010 3:34 PM
  •  

    We are currently working on this fix and it should be ready in the next week or so. To get the fix you will have to contact Microsoft at 800 936-5800begin_of_the_skype_highlighting            800 936-5800      end_of_the_skype_highlighting (select option 3) to open a case and request Fix number KB 361949. Note since this is a hotfix you will not be charged or decremented an incident. However, you are still required to open a case. Again the fix is not available now, but I will post again once the fix become ready.
    I called Microsoft, they said this is not a valid fix, nor can I find it when I search for it.

    Duane Lawrence

    Tuesday, 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