PersonalizationAdministration Class
Assembly: System.Web (in system.web.dll)
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.
| Topic | Location |
|---|---|
| How to: Remove User Entries from the Personalization Store | Building ASP .NET Web Applications |
| How to: Enable Users to Clear Personalization State | Building ASP .NET Web Applications |
| How to: Remove User Entries from the Personalization Store | Building ASP .NET Web Applications |
| How to: Enable Users to Clear Personalization State | Building ASP .NET Web Applications |
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> <asp:LoginName ID="LoginName1" runat="server" /> <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="RedirectToLoginPage" /> <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.
<%@ 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" /> <br /> <asp:TextBox ID="TextBox1" runat="server" Width="268px"></asp:TextBox> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="Scope" /> <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" /> <br /> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:Label ID="Label4" runat="server" Width="77px" ForeColor="Red" /> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Find User" OnClick="Button1_Click" /> <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" Height="21px" /> <br /> <asp:TextBox ID="TextBox4" runat="server" Width="63px"></asp:TextBox> <br /> <br /> <br /> <br />
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.