Export (0) Print
Expand All

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)

public static class PersonalizationAdministration
public final class PersonalizationAdministration
public final class PersonalizationAdministration
Not applicable.

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.

TopicLocation
How to: Remove User Entries from the Personalization StoreBuilding ASP .NET Web Applications
How to: Enable Users to Clear Personalization StateBuilding ASP .NET Web Applications
How to: Remove User Entries from the Personalization StoreBuilding ASP .NET Web Applications
How to: Enable Users to Clear Personalization StateBuilding ASP .NET Web Applications
How to: Enable Users to Clear Personalization StateBuilding ASP .NET Web Applications in Visual Studio

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.

Security noteSecurity 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 (Visual Studio).

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

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

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft