Administrating Personalization


A public website that uses Web Parts might have thousands of members. Each member, potentially, could personalize multiple pages in the website.

Most public websites experience significant churn. A person registers at the website, plays around with it for a few minutes, and then leaves without ever being seen again. Saving personalization data for inactive users could be a huge waste of resources.

The Web Part Framework includes a PersonalizationAdministration class. This class includes several valuable methods for identifying and pruning inactive personalization data. Here is a list of the methods supported by this class:

  • FindInactiveUserState Returns a collection of User personalization state information when supplied with path, username, and date parameters. This method supports wildcards in its parameters.

  • FindSharedState Returns a collection of Shared personalization state information when supplied with a path. This method supports wildcards in its path parameter.

  • FindUserState Returns a collection of User personalization state information when supplied with a path and username. This method supports wildcards in its parameters.

  • GetAllInactiveUserState Returns a collection of User personalization state information when supplied with a date.

  • GetAllState Returns a collection of personalization state information when supplied with a personalization scope.

  • GetCountOfInactiveUserState Returns the number of user personalization items older than the supplied date parameter.

  • GetCountOfState Returns the number of user personalization items matching a particular personalization scope.

  • GetCountOfUserState Returns the number of user personalization items matching a certain username. This method supports wildcards in the username parameter.

  • ResetAllState Deletes personalization information matching a particular personalization scope.

  • ResetInactiveUserState Deletes User personalization data older than the supplied date parameter.

  • ResetSharedState Deletes Shared state information that matches the supplied path parameter.

  • ResetState Deletes state information that matches the contents of the supplied parameter, which represents a collection of state information.

  • ResetUserState Deletes state information that matches either the supplied username or path parameters.

The ResetAllState() method is the nuclear bomb of personalization administration methods. You can use this method to blow away all User and Shared state information for all users.

The other methods are useful for pruning stale state information. The page in Listing 29.10 illustrates how you can retrieve personalization state information for a particular user.

Listing 29.10. AdministerPersonalization.aspx

[View full width]

<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server">     Protected  Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)         GridView1.DataSource = PersonalizationAdministration.FindUserState(Nothing,  txtUsername.Text)         GridView1.DataBind()     End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head  runat="server">     <style type="text/css">         .grid         {             font: 14px Arial, Sans-Serif;         }         .grid td         {             padding:10px;         }         .grid th         {             padding:10px;             background-color:orange;             text-align:left;         }     </style>     <title>Administer Personalization</title> </head> <body>     <form  runat="server">     <div>     <asp:Label                  AssociatedControl         Text="Username:"         Runat="server" />     <asp:TextBox                  Runat="server" />     <asp:Button                  Text="Submit"         OnClick="btnSubmit_Click"         Runat="server" />     <hr />     <asp:GridView                  Css         Runat="server" />     </div>     </form> </body> </html> 

If you enter a username in the form contained in Listing 29.10 and click the Submit button, matching personalization items are displayed by the GridView control (see Figure 29.5). The FindUserState() method is used to retrieve the matching personalization items.

Figure 29.5. Displaying personalization data.





ASP. NET 2.0 Unleashed
ASP.NET 2.0 Unleashed
ISBN: 0672328232
EAN: 2147483647
Year: 2006
Pages: 276

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net