WebPart Personalization Blob Deserialize Error

Discussion in 'ASP .Net Web Controls' started by Tom John, Jul 3, 2007.

  1. Tom John

    Tom John Guest

    Hi

    We're trying to maually deserialize the Personalization Blob for WebParts,
    seemed pretty straight forward, however we get the error "The serialized data
    is invalid." from the following code:

    <code>
    Using connection As New SqlConnection(My.Settings.Conn)
    connection.Open()

    Using Command As New SqlCommand("SELECT PageSettings FROM
    aspnet_PersonalizationAllUsers", connection)

    Using reader As SqlDataReader = Command.ExecuteReader()

    While reader.Read()

    Dim data As String =
    Convert.ToBase64String(CType(reader(0), Byte()))
    Dim formatter As New ObjectStateFormatter()
    formatter.Deserialize(data)

    End While

    End Using

    End Using

    End Using
    </code>

    Anyone got any ideas on how you're supposed to crack this one?

    Cheers

    Tom
    Tom John, Jul 3, 2007
    #1
    1. Advertising

  2. Hi Tom,

    From your description, you're writing your custom code to load binary data
    from ASP.NET webpart personalization database and deserialize againstit,
    however,you're encountering some error on it , correct?

    Based on my understanding, it is only when you developing a custom
    personalization provider or customize the existing one will you need to
    deal with the underlying binary data blob's load & store. So are you
    developing your custom webpart personalization provider?

    If you're customizing the default SQL personalization provider or also use
    the same database, you can have a look at the built-in provider's code
    implementation on how to retrieve the binary blob from database. Here is
    the code I picked from reflector (of the SqlPersonalizationProvider class)

    ==================================
    private byte[] LoadPersonalizationBlob(SqlConnection connection, string
    path, string userName)
    {
    SqlCommand command;
    if (userName != null)
    {
    command = new
    SqlCommand("dbo.aspnet_PersonalizationPerUser_GetPageSettings", connection);
    }
    else
    {
    command = new
    SqlCommand("dbo.aspnet_PersonalizationAllUsers_GetPageSettings",
    connection);
    }
    this.SetCommandTypeAndTimeout(command);
    command.Parameters.Add(this.CreateParameter("@ApplicationName",
    SqlDbType.NVarChar, this.ApplicationName));
    command.Parameters.Add(this.CreateParameter("@Path",
    SqlDbType.NVarChar, path));
    if (userName != null)
    {
    command.Parameters.Add(this.CreateParameter("@UserName",
    SqlDbType.NVarChar, userName));
    command.Parameters.Add(this.CreateParameter("@CurrentTimeUtc",
    SqlDbType.DateTime, DateTime.UtcNow));
    }
    SqlDataReader reader = null;
    try
    {
    reader = command.ExecuteReader(CommandBehavior.SingleRow);
    if (reader.Read())
    {
    int length = (int) reader.GetBytes(0, (long) 0, null, 0, 0);
    byte[] buffer = new byte[length];
    reader.GetBytes(0, (long) 0, buffer, 0, length);
    return buffer;
    }
    }
    finally
    {
    if (reader != null)
    {
    reader.Close();
    }
    }
    return null;
    }
    =========================================

    Also, here are some other reference on building custom personalization
    provider:

    http://msdn2.microsoft.com/en-US/library/aa479037.aspx

    http://msdn.microsoft.com/msdnmag/issues/05/09/WebParts/

    Hope this helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jul 4, 2007
    #2
    1. Advertising

  3. Tom John

    Tom John Guest

    Steven

    Thanks for you reply. I can see where you are going with this, however what
    we're trying to do is way simpler. We're using the standard provider and
    everything's working fine for the regular webpart customization scenario.

    However, we are working on some utilities to provide the webmaster, one of
    which needs to search the properties of the webparts on a page for certain
    string values. So I want to desterilize the blob into the object graph and
    iterate through the properties.

    There is an article that suggests this has been achieved before, however it
    does not tell the full story on how to do it:

    http://dotnetjunkies.com/WebLog/teund/archive/2005/03/08/WebPartManager_Storage.aspx

    Hope this makes it a little clearer?

    Thanks

    Tom John
    "Steven Cheng[MSFT]" wrote:

    > Hi Tom,
    >
    > From your description, you're writing your custom code to load binary data
    > from ASP.NET webpart personalization database and deserialize againstit,
    > however,you're encountering some error on it , correct?
    >
    > Based on my understanding, it is only when you developing a custom
    > personalization provider or customize the existing one will you need to
    > deal with the underlying binary data blob's load & store. So are you
    > developing your custom webpart personalization provider?
    >
    > If you're customizing the default SQL personalization provider or also use
    > the same database, you can have a look at the built-in provider's code
    > implementation on how to retrieve the binary blob from database. Here is
    > the code I picked from reflector (of the SqlPersonalizationProvider class)
    >
    > ==================================
    > private byte[] LoadPersonalizationBlob(SqlConnection connection, string
    > path, string userName)
    > {
    > SqlCommand command;
    > if (userName != null)
    > {
    > command = new
    > SqlCommand("dbo.aspnet_PersonalizationPerUser_GetPageSettings", connection);
    > }
    > else
    > {
    > command = new
    > SqlCommand("dbo.aspnet_PersonalizationAllUsers_GetPageSettings",
    > connection);
    > }
    > this.SetCommandTypeAndTimeout(command);
    > command.Parameters.Add(this.CreateParameter("@ApplicationName",
    > SqlDbType.NVarChar, this.ApplicationName));
    > command.Parameters.Add(this.CreateParameter("@Path",
    > SqlDbType.NVarChar, path));
    > if (userName != null)
    > {
    > command.Parameters.Add(this.CreateParameter("@UserName",
    > SqlDbType.NVarChar, userName));
    > command.Parameters.Add(this.CreateParameter("@CurrentTimeUtc",
    > SqlDbType.DateTime, DateTime.UtcNow));
    > }
    > SqlDataReader reader = null;
    > try
    > {
    > reader = command.ExecuteReader(CommandBehavior.SingleRow);
    > if (reader.Read())
    > {
    > int length = (int) reader.GetBytes(0, (long) 0, null, 0, 0);
    > byte[] buffer = new byte[length];
    > reader.GetBytes(0, (long) 0, buffer, 0, length);
    > return buffer;
    > }
    > }
    > finally
    > {
    > if (reader != null)
    > {
    > reader.Close();
    > }
    > }
    > return null;
    > }
    > =========================================
    >
    > Also, here are some other reference on building custom personalization
    > provider:
    >
    > http://msdn2.microsoft.com/en-US/library/aa479037.aspx
    >
    > http://msdn.microsoft.com/msdnmag/issues/05/09/WebParts/
    >
    > Hope this helps.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    Tom John, Jul 4, 2007
    #3
  4. Thanks for your reply Tom,

    Well, after read the article you provided, I think what you want to do is
    accessing the serialized data(manually deserialized it) in a non-ASP.NET
    context,correct?

    For this scenario, I'm afraid I haven't quite got any definite reference on
    manually inspect the webpart service's serialized binary data ourself.
    Currently the data webpart manager's serialized dataformat hasn't bee well
    documented and manually crack it out may cause some unexpected problem.
    BTW, have you tried using the serializing code picked from the built-in
    SqlPersonalizationProvider? It causes those predefined store precedures to
    get the binary blob.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jul 6, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y3RhZGxvY2s=?=

    WebPart Portal Personalization?

    =?Utf-8?B?Y3RhZGxvY2s=?=, Mar 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    611
    =?Utf-8?B?Y3RhZGxvY2s=?=
    Mar 24, 2005
  2. Leroy
    Replies:
    1
    Views:
    1,881
    Daniel TIZON
    Dec 16, 2005
  3. Electrified Research
    Replies:
    3
    Views:
    555
    Electrified Research
    Sep 23, 2006
  4. Bei
    Replies:
    0
    Views:
    398
  5. =?Utf-8?B?U2hhbg==?=

    Personalization webpart

    =?Utf-8?B?U2hhbg==?=, May 18, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    342
    =?Utf-8?B?U2hhbg==?=
    May 18, 2007
Loading...

Share This Page