Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

Rate It (17)

Last post 10-15-2009 2:14 AM by hemant.yadav. 311 replies.

Sort Posts:

  • Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-19-2006, 9:33 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    hey folk,

    maybe you can help me with the following prob:
    i developped a "job search application" in asp.net 2.0 beta. it compiled and ran without any problems. now, with the new asp.net 2.0 final version, i'm getting a lot this error message:

    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.

    this error is only generated if you navigate quickly through the web application. that means, if you press an <asp:Button> before the whole page is loaded/rendered, then you get this posted error. if you wait until the whole page has finished rendering, then the postback generates no errors.
     
    i've read a lot of articles and forum posts, and nothing figured out the problem:
    - NO, i'm not running a Web Farm.
    - page property "EnableViewStateMac" set to false does not solve the problem, it just changes the error message in same navigation behaviour:

    The state information is invalid for this page and might be corrupted.

    the second error could be solved with hotfixes/updates in asp.net 1.0/1.1
    is there also a solution available for asp.net 2.0 final version?

    thanks for helping!

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-20-2006, 7:31 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    further information about my problem:

    i've done a lot of test cases in recently past hours, following i found out concerning my problem:
    it depends on which webcontrols you have in use in an asp.net 2.0 final application. my reported problem only occurs if you've nested a gridview, a detailview or a formview within the *.aspx page. and it does not even matter if they are bound to a datasource control. they fail in both cases (bound / unbound) if you navigate too quickly (have a look at first post for its explanation).

    conclusion:
    my problem has too be a general one in asp.net 2.0 final framework. i'm working in a small developping team for web solutions. and we've figured out that all our asp.net applications (which were running fine in asp.net beta 2.0) have this problem :-( error message "Validation of viewstate MAC failed" occurs in simple page architecture (no masterpages, no callbacks etc.) even!
    i'm sure other developers are also hit, aren't they?

    special remark:
    although we have NO webfarm in use, i've also tried to use a self-generated <machinekey> in web.config. no success as expected ;-) 

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-23-2006, 4:44 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    ... and again me :-)

    it would also be helpful to receive replies which confirm my "observations" about this asp.net error message - even if you haven't found the solution. thanks
    .

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-24-2006, 7:35 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    What a 'tiny' bug...

    today, i found out under which exact circumstances the reported error raises.
    it all belongs to the DataKeyNames property!

    if you don't use this property, you will never get that "Validation of viewstate MAC failed" error by navigating quickly (do postback before whole page has finished rendering).
    so, all you need on an *.aspx page for generating this error:

    1. SqlDataSource
    2. GridView bound to SqlDataSource
    3. Using DataKeyNames in GridView
    4. Something on the *.aspx page which takes a while till rendered (as for example banners, external pictures etc.)
    5. Button*

    * you can also do a postback with the GridView's sorting command.


    final conclusion:
    that must be a bug in the .net framework! MVP users or others... what do you think about? 

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-24-2006, 8:08 PM
    • Member
      30 point Member
    • xpedite
    • Member since 01-24-2006, 12:16 AM
    • Posts 6
    Lots of people waiting for an answer to this one. Is it something that is know and being fixed or are we all just completely lost and should give up and go back to 1.1?
  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-25-2006, 4:06 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    "Lots of people waiting for an answer"

    glad reading this. unfortunately i've never found any articles, forum posts complaining about exactly the facts/bug i described.

    i hope more people are gonna confirm this thread, so microsoft experts will give reply - thanks!

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-26-2006, 11:56 AM
    • Member
      25 point Member
    • devMonky2k
    • Member since 01-05-2006, 2:36 PM
    • Posts 6

    Hi crystal.net,

     

    I can confirm I get exactly the same error.

     

    My page that errors has a GridView bound to an ObjectDataSource. This is a custom GridView which uses a dropdown outside it (with numbers 1 to 20) and an add button next to it. This allows users to add up to 20 rows to the grid at a time. In the background each 'add' creates a new object and stuffs it into my generic list which is bound to the ObjectDataSource. Each row in the Grid has LOTS of DropDownLists, Labels, TextBox controls, Imagebuttons etc . After you add about 30 row the page render time dramatically increase (as you'd expect). Once you edit a number of these controls and click the submit button the error occurs. The submit saves the items in my generis list to sql then reloads itself with a empty generic list.

     

    Validation of ViewState errors occur on our office server (when being tested) as if it were a production environment. And it doesn't happen everytime either?!?! When I test the site using my locahost I cannot reproduce this error.

     

    We are not using a web farm and site is built in debug mode in all cases (but will be in release mode when live on production server). This happens when you try to submit the page even when it has DEFINITELY finished loading so how can the viewstate be different than on the server? I admit the ViewState is pretty hefty. Is this an isolated problem with GridViews and ViewState?

     

    We have experience other problem with EventValidation. A workaround for these was to set <pages enableEventValidation="false"/> in web.config

     

    I have spent far too long trawling the internet for a solution but nothing!!!

     

    Can someone at MICROSOFT please confirm if this a bug in the .net 2.0 framework and if so what can we do to STOP it!!

     

    I need a solution FAST!

     

    Thanks

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-27-2006, 3:05 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20

    hey devMonky2k,

    thanks for your post. you haven't written it, but i'm very sure you also have the property DataKeyNames in your GridView in use.... and i had to laugh if i read about your EventValidation problem. i had the same problem and workaround, too :-)

    so i think it's evidence enough, microsoft supporters, we'd appreciate your help!!

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-27-2006, 12:59 PM
    • Member
      10 point Member
    • JustDrums
    • Member since 01-27-2006, 5:53 PM
    • Posts 2

    Hey Crystal,

    I'm happy to see that I am not the only one experiencing this with .net 2.0.  I love this new dev environment but it appears as though little bugs are still present with designer based controls.

    I'm using a gridview bound to a SqlSource, have tried all the workarounds (MachineKey, etc) and I am still getting the error on what appears to be anything postback. When I sort my grid, the error occurs, and I assume it has to do with viewstate.

    I read a MS article somewhere that explained how data conversions or formatting might have an impact (ie. converting int to string for example) but this originally appeared to be with .Net 1.0 and the article dates back some time.

    I guess no sorting for the time being until this gets resolved.

    If I find anything, I'll post.

    Cheers.

     

    /JD

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-30-2006, 12:16 PM
    • All-Star
      46,032 point All-Star
    • joteke
    • Member since 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,879
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs
    crystal.net wrote:

     

    1. SqlDataSource
    2. GridView bound to SqlDataSource
    3. Using DataKeyNames in GridView
    4. Something on the *.aspx page which takes a while till rendered (as for example banners, external pictures etc.)
    5. Button*

    I tried to locally reproduce with these steps, and I couldn't get the same to appear. Does this happen locally or only on remote server (Windows Server 2003 utilizing application pools?) Perhaps you could show the entire page, if it is reproducable with a small sample page.

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-31-2006, 9:11 AM
    • Member
      100 point Member
    • crystal.net
    • Member since 01-19-2006, 1:11 PM
    • Posts 20
    hey joteke,

    thanks for taking time! i've spent the morning for reproducing a small sample page that points out the reported bug. i used a <asp:XmlDataSource> instead of <asp:SqlDataSource> for make it independent of any configuration ressources. you can download the source here: http://www.espace.ch/viewstateProblem.rar

    you have to click very quickly (serveral times) in doing the postback for reproducing the bug in the sample page!!!

    for those guys who think the navigation behavior strange... yeah, you're right: in the given sample page, it is really silly n' difficult navigating so quickly (pressing button before page has finished rendering!!). but if you look at the final application (http://adv.espace.ch/einsteigerprofil), you'll see that reported navigation behavior is common: the standard shape/design of espace.ch takes an amount of time for loading - and i don't think users are gonna wait until page has finished rendering each time.

    last but not least i have to correct my observations!
    so, all you need on an *.aspx page for generating this error:
    1. Any DataSource Control (SqlDataSource, XmlDataSource...) 
    2. GridView bound / unbound to DataSource
    3. Using DataKeyNames in GridView
    4. Using <asp:BoundField> elements
    5. Something on the *.aspx page which takes a while till rendered (as for example banners, external pictures etc.)
    6. Button
  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-31-2006, 12:59 PM
    • All-Star
      46,032 point All-Star
    • joteke
    • Member since 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,879
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Yes, I got this one to reproduce with the set you gave.

    Let me test it a little bit more.

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-31-2006, 1:04 PM
    • All-Star
      46,032 point All-Star
    • joteke
    • Member since 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,879
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Ok,

    if you guys add this to web.config, does it still reproduce?

    <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

    E.g note the viewStateEncryptionMode.

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-31-2006, 1:39 PM
    • Member
      10 point Member
    • JustDrums
    • Member since 01-27-2006, 5:53 PM
    • Posts 2

    Hi Joteki,

    The error is ever present in my case. I get the typical "Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation." whether enableEventValidation is set to true or false.

    One thing worth noting:  My page actually has three different controls, all seperate and none linked or nested - 1 Gridview and 2 datalists. If I take a new aspx, create a simple gridview bound to the same view in SQL, and try sorting (my problem occurs on the sort), everything rolls fine. But in my original .aspx, I get the error.

    So I removed the controls in order to slowly start "removing possible conflicts" and suddently, the sort in my Gridview worked without a hitch. I put the datalist back and the error returned.

    Thinking I was on to something, I removed all datalists and gridview from my original .aspx as well as SqlSources. I then proceeded to add my Gridview and the error returned WITHOUT the datalists.

    This REALLY appears to be a bug in .Net 2.0, and I've yet to figure out why exactly it happens. Isolating it appears impossible.

    The only workaround I can suggest is to "think outside of the box" and try placing your controls in other ways, or redo the page altogether.

    I have had other bugs where a simple bound dropdownlist would not function properly until I literally "Deleted" the Usercontrol (.ascx) from my project, created a new one and the DDL functioned properly moving forward.

    Servicepack anyone?

    /JD

  • Re: Validation of viewstate MAC failed / The state information is invalid for this page and might be corrupted

    01-31-2006, 2:56 PM
    • Contributor
      5,525 point Contributor
    • Eilon
    • Member since 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 951
    • AspNetTeam

    Hi everyone,

    The error that's happening (as has been mentioned earlier) is caused by an ASP.net 2.0 feature called Event Validation. This is a security feature that ensures that postback actions only come from events allowed and created by the server to help prevent spoofed postbacks. This feature is implemented by having controls register valid events when they render (as in, during their actual Render() methods). The end result is that at the bottom of your rendered <form> tag, you'll see something like this:

     <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="AEBnx7v.........tS" />

    When a postback occurs, ASP.net uses the values stored in this hidden field to ensure that the button you clicked invokes a valid event. If it's not valid, you get the exception that you've been seeing.

    The problem you're seeing happens specifically when you postback before the EventValidation field has been rendered. If EventValidation is enabled (which it is, by default), but ASP.net doesn't see the hidden field when you postback, you also get the exception. If you submit a form before it has been entirely rendered, then chances are the EventValidation field has not yet been rendered, and thus ASP.net cannot validate your click.

    One work around is of course to just disable event validation, but you have to be aware of the security implications. Alternatively, just never post back before the form has finished rendering. Of course, that's hard to tell your users, but perhaps you could disable the UI until the form has rendered?

    Unfortunately there's no "perfect" solution for this just yet.

    Thanks,

    Eilon

     

    Blog: http://weblogs.asp.net/LeftSlipper/
Page 1 of 21 (312 items) 1 2 3 4 5 Next > ... Last ยป