views:

571

answers:

2

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 :)

+1  A: 

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;
}
bendewey
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...
Gregorius
You won't be hitting the database everytime. Thats what the caching is for.
bendewey
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
One more options is to set the EnableViewStateMac="false"
bendewey
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!!!
Gregorius
A: 

Hi,

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

afgallo
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.
Gregorius