3

I have a page which contains some search fields to query a database, and display results. The viewstate is required to retain the lists of items in dropdowns.

Everything works fine in Firefox (3) & Chrome, but fails in Internet Explorer, but only sometimes (certain actions, such as resetting the form, which really just does a response.redirect with some querystring parameters)... what happens in the Viewstate gets dumped on the URL, and an error page is thrown.

Has anybody come across this before? Perhaps some pointers as to what might be causing this to occur in IE?

Thanks heaps,

greg

UPDATE:

On further investigation, i have determined that the actual error is this:

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

Some more information that might help: This is caused by a user control that is being hosted in a content management system (Umbraco), which might have something to do with why the viewstate is being passed to the page (as the control is contained within a greater page in the CMS). I will investigate this a little further, but any other suggestions would be much appreciated.

cheers greg

UPDATE 2:

Can anybody suggest why this only happens in IE (and not in FF or Chrome)?? Seems hardly likely its an issue with controls changing or machine keys or other suggestions I've read around the place, if other browsers can deal with it fine.

Any ideas what IE does differently that could cause this failure??

SOLUTION:

Turns out it was a really silly problem - I was using the wrong master template in the CMS, and therefore had 2 form tags. Remove extra form tag, problem solved!

Thanks heaps to bendewey for helping me solve this problem (see the comments in bendewey's post).

That's 4 hours of my life i'd love to get back... but glad i can move on now. Thanks again Stack Overflow community :)

2
  • It would help if you could explain a bit more about the redirection and explain what you mean about "dumping the viewstate on the URL".
    – jeremcc
    Feb 11, 2009 at 4:05
  • redirect is as follows: Response.Redirect(String.Concat(strPageUrl, "?reset=true")); what it did was something like this: domain/page.aspx?_VIEWSTATE=afdfkhadkjhqkjdasf Anyway its solved - was caused by multiple form tags (as mentioned above)
    – Jeeby
    Feb 11, 2009 at 6:03

3 Answers 3

1

It seems a bit wierd that your viewstate is posting to the the Url. The would happen if you had some custom form tag that was using a GET method instead of the default asp.net page level form tag.

If you need a form tag with the GET method I would set EnableViewState="false" on the Page declaration and setup some sort of list caching. Here is a sample, but you can find much better samples online (specifically ones that do double check locking). This way you can call this every postback and not worry about storing anything in the viewstate.

List<string> getCachedFields()
{
    var searchFields = Cache["searchFields"] as List<string>;
    if (searchFields == null)
    {
        searchFields = GetFieldsFromDbOrSomewhereExpensive();
        Cache["searchFields"] = searchFields;
    }
    return searchFields;
}
5
  • hmmm... i'm not crazy about the idea of hitting a database or other expensive data store every time the page is loaded - far from ideal. More info in next post...
    – Jeeby
    Feb 11, 2009 at 4:31
  • You won't be hitting the database everytime. Thats what the caching is for.
    – bendewey
    Feb 11, 2009 at 4:46
  • 1
    Also can you check your source and make sure you don't have 2 form tags maybe. I've never seen this, but its not unlikely that different browsers could act differently with multiple form tags.
    – bendewey
    Feb 11, 2009 at 4:48
  • One more options is to set the EnableViewStateMac="false"
    – bendewey
    Feb 11, 2009 at 4:49
  • WWWWWWOOOOOOWWWWWW - dude, i'm seriously impressed! Are you a professional needle in a haystack spotter? I did indeed have 2 form tags (was using the wrong master template) - removing this has fixed the problem! THANK YOU SO MUCH - YOU ROCK!!!
    – Jeeby
    Feb 11, 2009 at 5:03
1

We've fixed this problem using this blog's suggestion. Please have a look at it ...

1
  • Thanks for the link, however i dont believe this is the issue as i'm running locally, and its definitely loading the full page - it has nothing to do with the speed of the click.
    – Jeeby
    Feb 11, 2009 at 4:59
0

I had to remove EnableViewStateMac="false" from the <pages> element to avoid the error in IE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.