Odd ViewState timeout issue?

2 posts, 0 answers
  1. James Legan
    James Legan avatar
    54 posts
    Member since:
    Sep 2008

    Posted 25 Mar 2009 Link to this post

    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"];

  2. Todd Anglin
    Todd Anglin avatar
    2040 posts
    Member since:
    Aug 2005

    Posted 26 Mar 2009 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top