Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Inherited Page class's LoadPageStateFromPersistenceMedium method not firing

Back to Forum: Tech Off
  • User profile image
    W3bbo

    I've developed a class that inherits System.Web.UI.Page and specified the following overloads:

    -------------------------------------------

        Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
           
            Dim strViewState As String = HttpContext.Current.Request.Form("__VIEWSTATE").ToString()
           
            If strViewState = Nothing Then
                Return Nothing
            End If
           
            Return Formatter.Deserialize(strViewState)
           
        End Function
       
        Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object)
           
            If Me.EnableViewState = True Then
                'Dim writer As New IO.StringWriter
               
                viewstateToSave = viewState
               
            End If
        End Sub


    -------------------------------------------

    The thing is, when I run the web-app I get this error:

    --------------------------------------------

    [HttpException (0x80004005): Unable to validate data.]
    System.Web.Configuration.MachineKey.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength) +196
    System.Web.UI.LosFormatter.Deserialize(String input) +60

    [HttpException (0x80004005): Authentication of viewstate failed. 1) If this is a cluster, edit <machineKey> configuration so all servers use the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. 2) Viewstate can only be posted back to the same page. 3) The viewstate for this page might be corrupted.]
    System.Web.UI.LosFormatter.Deserialize(String input) +117
    System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +102

    [HttpException (0x80004005): Invalid_Viewstate
    Client IP: 192.168.0.2
    Port: 2923
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
    ViewState: dDw1MzgxO3Q8O2w8aTwwPjs+O2w8dDw7bDxpPDE+Oz47bDx0PHA8bDxUZXh0Oz47bDxCbGVyZ2g7Pj47Oz47Pj47Pj47Pg==
    Http-Referer: http://proj/AMS/Redirector.aspx?404;http://proj:80/AMS/news/blergh
    Path: /AMS/Redirector.aspx.]
    System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +447
    System.Web.UI.Page.LoadPageViewState() +18
    System.Web.UI.Page.ProcessRequestMain() +447


    --------------------------------------------

    Clearly the ASP.NET runtime is executing Page.LoadViewStateFromPersistenceMedium rather than XPage.LoadViewStateFromPersistenceMedium because the Page.LoadViewState... method does a bit of trickery with the Machine Key for verification, yet I overloaded the method.

    ...so why isn't it being called?

  • User profile image
    W3bbo

    footballism wrote:
    You use the wrong deserialization mechanism to deserialize the state information, so when the ASP.NET runtime plans to decrypt the deserialized state information, it complains about the invalid state information, in actuality, ASP.NET runtime uses System.Web.UI.LosFormatter to serialize the deserialize the state information.

    Sheva


    Actually, I fixed this.

    The Formatter that I referenced is actually a LosFormatter, but the old LoadViewStateFromPersistenceMedium method is called because one of the pages involved in the page-redirection cycle inherits Page and not XPage.

    Since changing this, it now works Smiley

  • User profile image
    footballism

    You use the wrong deserialization mechanism to deserialize the state information, so when the ASP.NET runtime plans to decrypt the deserialized state information, it complains about the invalid state information, in actuality, ASP.NET runtime uses System.Web.UI.LosFormatter to serialize and deserialize the state information.

    Sheva

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.