This is a migrated thread and some comments may be shown as answers.

Odd ViewState timeout issue?

1 Answer 77 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James Legan
Top achievements
Rank 1
James Legan asked on 25 Mar 2009, 06:22 PM

Ok, I know the subject doesn't make sense, but I am at the point of ripping my hair out over this. I have a struct which contains other structs (also tag serializable) shown below. I am heavily using Telerik controls in this app and as the user follows this tab driven wizard, information from each tab is added to the TestConfig object in ViewState. This works flawlessly, until... you let the browser sit for 4 or so minutes. If at any point in time you sit on a particular tab and wait the requsite 240+ seconds, when the user clicks next, the debugger throws an InvalidCastException. Here is the interesting part. The cast is a simple return of the object from ViewState (below). The object in ViewState no longer thinks it is a TestConfig object. It will allow me to cast it as an object as it rightfully should and I can even drill down into the object within VS2008 and see all of the data is still there. Somehow it is losing its type and I cannot for the life of me figure it out. I am at the point of either moving to a database solution or if it doesn't make sense to do that, hidden controls, but I would really like to just resolve this the right way. Anyone have any thoughts?

Structs:

[Serializable]
    public struct TestConfig
    {
        public GridData oTestType;
        public GridData oArchitecture;
        public GridData oBuild;
        public GridData oBuildType;
        public List<GridData> gloLanguages;
        public List<GridData>  gloOperatingSystems;
        public List<GridData>  gloFamilies;
        public List<TestDriverData> gloTestDriverData;
    }

    [Serializable]
    public struct TestDriverData
    {
        public string sPath;
        public string sModel;
        public string sModelDisplayString;
        public string sPort;
        public string sPdl;
        public string sPdlDisplayString;
        public string sFamily;

    }

    [Serializable]
    public struct GridData
    {
        public string sDisplay;
        public string sData;
        public string sMisc;
    }
 

Return Code:

 

return (TestConfig)ViewState["m_TestConfig"];

1 Answer, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 27 Mar 2009, 04:23 AM
Hello James-

Definitely a strange problem. I see there is little additional help on the ASP.NET Forums for your question. :)

I have found that others have enountered a similar problem to yours (where ViewState seems to "timeout" after a long period of time):

http://naspinski.net/post/apparently-viewstate-variables-time-out.aspx

Clearly, ViewState cannot itself "timout." It's a static value. In fact, you can use a tool like ViewStateDecoder to decode serialized ViewState anytime you'd like. What causes problem is when ViewState is encrypted because the server's MachineKey is used. Ifyou're in a Web Farm environment, this value may not be consistent over time and thus cause decyrption problems. And apparently, according to the above referenced blog, you can even encounter problems outside of a web farm environment (go figure).

In any event, try these settings in your web.config and see if they help:

<pages enableViewStateMac="false" enableEventValidation="false" viewStateEncryptionMode ="Never" >

Hope that helps! If it doesn't, it may be time to investigate another non-ViewState solution...

-Todd
Tags
General Discussions
Asked by
James Legan
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Share this question
or