PersonalizationAdministration Class

Definition

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

public ref class PersonalizationAdministration abstract sealed
public static class PersonalizationAdministration
type PersonalizationAdministration = class
Public Class PersonalizationAdministration
Inheritance
PersonalizationAdministration

Examples

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.

Important

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);
        // <snippet4>
        _provider = PersonalizationAdministration.Provider.Name;
        TextBox1.Text = _provider;
        // </snippet4>
        // <snippet6>
        if (_manager.Personalization.Scope == PersonalizationScope.Shared)
        {
            TextBox2.Text = "Shared Scope";
        }
        else
            TextBox2.Text = "User Scope";
        // </snippet6>
           // <snippet5>
        Label4.Visible = false;
        TextBox4.Text = PersonalizationAdministration.GetCountOfState(PersonalizationScope.User).ToString();
            // </snippet5>
    }

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

    }
    // </snippet2>

</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 />

Remarks

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.

Properties

ApplicationName

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

Provider

Returns an instance of the default personalization provider.

Providers

Returns a collection of personalization providers indexed by name.

Methods

FindInactiveUserState(String, String, DateTime, Int32, Int32, Int32)

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

FindInactiveUserState(String, String, DateTime)

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

FindSharedState(String, Int32, Int32, Int32)

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

FindSharedState(String)

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

FindUserState(String, String, Int32, Int32, Int32)

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

FindUserState(String, String)

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

GetAllInactiveUserState(DateTime, Int32, Int32, Int32)

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

GetAllInactiveUserState(DateTime)

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

GetAllState(PersonalizationScope, Int32, Int32, Int32)

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

GetAllState(PersonalizationScope)

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

GetCountOfInactiveUserState(DateTime)

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

GetCountOfInactiveUserState(String, DateTime)

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

GetCountOfState(PersonalizationScope, String)

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

GetCountOfState(PersonalizationScope)

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

GetCountOfUserState(String)

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

ResetAllState(PersonalizationScope)

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

ResetInactiveUserState(DateTime)

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

ResetInactiveUserState(String, DateTime)

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

ResetSharedState(String)

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

ResetSharedState(String[])

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

ResetState(PersonalizationStateInfoCollection)

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

ResetUserState(String, String)

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

ResetUserState(String, String[])

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

ResetUserState(String)

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

ResetUserState(String[])

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

Applies to

See also