PersonalizationAdministration Class

 

Implements management and administrative functionality for Web Parts personalization. This class cannot be inherited.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

System.Object
  System.Web.UI.WebControls.WebParts.PersonalizationAdministration

public static class PersonalizationAdministration

NameDescription
System_CAPS_pubpropertySystem_CAPS_staticApplicationName

Gets or sets the name of the application specified by the provider.

System_CAPS_pubpropertySystem_CAPS_staticProvider

Returns an instance of the default personalization provider.

System_CAPS_pubpropertySystem_CAPS_staticProviders

Returns a collection of personalization providers indexed by name.

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticFindInactiveUserState(String, String, DateTime)

Returns a collection of per-user personalization state information for inactive users, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticFindInactiveUserState(String, String, DateTime, Int32, Int32, Int32)

Returns a collection of per-user personalization state information for inactive users, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticFindSharedState(String)

Returns a collection of shared personalization state information based on the specified path.

System_CAPS_pubmethodSystem_CAPS_staticFindSharedState(String, Int32, Int32, Int32)

Returns a collection of shared personalization state information based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticFindUserState(String, String)

Returns a collection of per-user personalization state information based on the user name and page path.

System_CAPS_pubmethodSystem_CAPS_staticFindUserState(String, String, Int32, Int32, Int32)

Returns a collection of per-user personalization state information based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticGetAllInactiveUserState(DateTime)

Returns a collection of all per-user personalization state information associated with inactive users, based on the specified date.

System_CAPS_pubmethodSystem_CAPS_staticGetAllInactiveUserState(DateTime, Int32, Int32, Int32)

Returns a subset of all per-user personalization state information associated with inactive users, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticGetAllState(PersonalizationScope)

Returns a collection of all personalization state information from the underlying data store for the requested personalization scope.

System_CAPS_pubmethodSystem_CAPS_staticGetAllState(PersonalizationScope, Int32, Int32, Int32)

Returns a subset of all personalization state information from the underlying data store, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticGetCountOfInactiveUserState(DateTime)

Returns a count of the per-user personalization items in the underlying data store for inactive users, based on the parameter specified.

System_CAPS_pubmethodSystem_CAPS_staticGetCountOfInactiveUserState(String, DateTime)

Returns a count of the per-user personalization items in the underlying data store for inactive users, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticGetCountOfState(PersonalizationScope)

Returns a count of the personalization state items in the underlying data store that exist for the specified scope.

System_CAPS_pubmethodSystem_CAPS_staticGetCountOfState(PersonalizationScope, String)

Returns a count of the personalization state items in the underlying data store that exist for the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticGetCountOfUserState(String)

Returns a count of the personalization state items in the underlying data store that exist for the specified user.

System_CAPS_pubmethodSystem_CAPS_staticResetAllState(PersonalizationScope)

Resets all personalization data in the underlying data store by deleting all rows associated with the specified scope.

System_CAPS_pubmethodSystem_CAPS_staticResetInactiveUserState(DateTime)

Resets all per-user personalization state information in the underlying data store, based on the specified parameter.

System_CAPS_pubmethodSystem_CAPS_staticResetInactiveUserState(String, DateTime)

Resets all per-user state information in the underlying data store for inactive users, based on the specified parameters.

System_CAPS_pubmethodSystem_CAPS_staticResetSharedState(String)

Resets shared state in the underlying data store for the specified path.

System_CAPS_pubmethodSystem_CAPS_staticResetSharedState(String[])

Resets shared state in the underlying data store for the specified paths.

System_CAPS_pubmethodSystem_CAPS_staticResetState(PersonalizationStateInfoCollection)

Resets personalization data in the underlying data store, based on the items contained in the collection.

System_CAPS_pubmethodSystem_CAPS_staticResetUserState(String)

Resets all per-user state in the underlying data store for the specified path.

System_CAPS_pubmethodSystem_CAPS_staticResetUserState(String, String)

Resets per-user state in the underlying data store for the specified combination of user name and path.

System_CAPS_pubmethodSystem_CAPS_staticResetUserState(String, String[])

Resets per-user state in the underlying data store for the page and users specified.

System_CAPS_pubmethodSystem_CAPS_staticResetUserState(String[])

Resets all per-user state in the underlying data store for the specified paths.

This class provides several static methods and properties that expose management and administrative functionality for Web Parts personalization. These methods apply to the default personalization provider configured in the WebPartManager control for a Web Parts control. If you need to administer several data stores that are acting as personalization providers, you should use the methods on the individual personalization provider classes directly. Note that the collection of configured personalization providers for a WebPartManager control is available from the Providers static property.

It is important to be aware that personalization will fail if your Web application does not run at the default trust level of Medium or higher (you can set custom trust levels in a Web.config file using the <trust level="" /> element). The PersonalizationAdministration and SqlPersonalizationProvider classes both check for a trust level of Low when they are initialized. If you configure your application to run at a trust level of Low, and you use the default SqlPersonalizationProvider provider to manage the personalization data for your application, the first time that the application tries to access personalization data, it will fail because an ASP.NET worker process running in Low trust does not have the permissions necessary to call into the various classes in the System.Data.SqlClient namespace.

The following code example demonstrates how to use several methods in the PersonalizationAdministration class. This example consists of an .aspx page that references a Web Parts user control named Persadmin.ascx. The following code provides the .aspx file for the example.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="admin" TagName="administrator" Src="~/PersAdmin.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
       <div>
        &nbsp;<asp:LoginName ID="LoginName1" runat="server" />
        &nbsp;
        <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="RedirectToLoginPage" />
        &nbsp;&nbsp;&nbsp;&nbsp;<br />
        <br />
        </div>
        <asp:WebPartManager ID="WebPartManager1" runat="server"></asp:WebPartManager>
        <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
        <admin:administrator id="admincontrol" runat="server" />
        </ZoneTemplate>
        </asp:WebPartZone>
    </form>
</body>
</html>

This code provides the Persadmin.ascx control.

System_CAPS_security Security Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Control Language="C#" ClassName="PersAdmin" %>

<script runat="server">
    WebPartManager _manager;
    string _provider;
    string _userscope;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }

    void InitComplete(object sender, System.EventArgs e)
    {
        _manager = WebPartManager.GetCurrentWebPartManager(Page);
        _provider = PersonalizationAdministration.Provider.Name;
        TextBox1.Text = _provider;
        if (_manager.Personalization.Scope == PersonalizationScope.Shared)
        {
            TextBox2.Text = "Shared Scope";
        }
        else
            TextBox2.Text = "User Scope";
        Label4.Visible = false;
        TextBox4.Text = PersonalizationAdministration.GetCountOfState(PersonalizationScope.User).ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox3.Text != null)
        {
            PersonalizationStateInfoCollection findresult;
          findresult = PersonalizationAdministration.FindUserState(null, TextBox3.Text);
          if (findresult.Count != 0)
          {
              Label4.Text = findresult.Count + "  user(s) found";
              Label4.Visible = true;
          }
          else
          {
              Label4.Text = "No users found.";
              Label4.Visible = true;
          }
        }
      else
      {
          Label4.Text = "You must enter a user name to find.";
      }

    }

</script>
<asp:Label ID="Label1" runat="server" Text="Personalization Provider" Width="162px"
  AssociatedControlID="TextBox1" />
<br />
<asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Scope" AssociatedControlID="TextBox2" />
<br />
<asp:TextBox ID="TextBox2" runat="server" Width="90px"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="User to Find" Width="135px"
  AssociatedControlID="TextBox3" />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
&nbsp;
<asp:Label ID="Label4" runat="server" Width="77px" ForeColor="Red" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Find User" OnClick="Button1_Click" />&nbsp;&nbsp;&nbsp;
<br />
<br />
<asp:Label ID="Label5" runat="server" Text="Personalization Statistics" Width="204px" />
<br />
<br />
<asp:Label ID="Label6" runat="server" Text="Number of User Personalization States" Width="246px"
  AssociatedControlID="TextBox4" Height="21px" />
<br />
<asp:TextBox ID="TextBox4" runat="server" Width="63px"></asp:TextBox>
<br />
<br />
<br />
<br />

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: