Export (0) Print
Expand All

PersonalizationAdministration Class

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

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

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

public static class PersonalizationAdministration

The PersonalizationAdministration type exposes the following members.

  NameDescription
Public propertyStatic memberApplicationNameGets or sets the name of the application specified by the provider.
Public propertyStatic memberProviderReturns an instance of the default personalization provider.
Public propertyStatic memberProvidersReturns a collection of personalization providers indexed by name.
Top

  NameDescription
Public methodStatic memberFindInactiveUserState(String, String, DateTime)Returns a collection of per-user personalization state information for inactive users, based on the specified parameters.
Public methodStatic memberFindInactiveUserState(String, String, DateTime, Int32, Int32, Int32)Returns a collection of per-user personalization state information for inactive users, based on the specified parameters.
Public methodStatic memberFindSharedState(String)Returns a collection of shared personalization state information based on the specified path.
Public methodStatic memberFindSharedState(String, Int32, Int32, Int32)Returns a collection of shared personalization state information based on the specified parameters.
Public methodStatic memberFindUserState(String, String)Returns a collection of per-user personalization state information based on the user name and page path.
Public methodStatic memberFindUserState(String, String, Int32, Int32, Int32)Returns a collection of per-user personalization state information based on the specified parameters.
Public methodStatic memberGetAllInactiveUserState(DateTime)Returns a collection of all per-user personalization state information associated with inactive users, based on the specified date.
Public methodStatic memberGetAllInactiveUserState(DateTime, Int32, Int32, Int32)Returns a subset of all per-user personalization state information associated with inactive users, based on the specified parameters.
Public methodStatic memberGetAllState(PersonalizationScope)Returns a collection of all personalization state information from the underlying data store for the requested personalization scope.
Public methodStatic memberGetAllState(PersonalizationScope, Int32, Int32, Int32)Returns a subset of all personalization state information from the underlying data store, based on the specified parameters.
Public methodStatic memberGetCountOfInactiveUserState(DateTime)Returns a count of the per-user personalization items in the underlying data store for inactive users, based on the parameter specified.
Public methodStatic memberGetCountOfInactiveUserState(String, DateTime)Returns a count of the per-user personalization items in the underlying data store for inactive users, based on the specified parameters.
Public methodStatic memberGetCountOfState(PersonalizationScope)Returns a count of the personalization state items in the underlying data store that exist for the specified scope.
Public methodStatic memberGetCountOfState(PersonalizationScope, String)Returns a count of the personalization state items in the underlying data store that exist for the specified parameters.
Public methodStatic memberGetCountOfUserStateReturns a count of the personalization state items in the underlying data store that exist for the specified user.
Public methodStatic memberResetAllStateResets all personalization data in the underlying data store by deleting all rows associated with the specified scope.
Public methodStatic memberResetInactiveUserState(DateTime)Resets all per-user personalization state information in the underlying data store, based on the specified parameter.
Public methodStatic memberResetInactiveUserState(String, DateTime)Resets all per-user state information in the underlying data store for inactive users, based on the specified parameters.
Public methodStatic memberResetSharedState(String)Resets shared state in the underlying data store for the specified path.
Public methodStatic memberResetSharedState(String[])Resets shared state in the underlying data store for the specified paths.
Public methodStatic memberResetStateResets personalization data in the underlying data store, based on the items contained in the collection.
Public methodStatic memberResetUserState(String)Resets all per-user state in the underlying data store for the specified path.
Public methodStatic memberResetUserState(String[])Resets all per-user state in the underlying data store for the specified paths.
Public methodStatic memberResetUserState(String, String)Resets per-user state in the underlying data store for the specified combination of user name and path.
Public methodStatic memberResetUserState(String, String[])Resets per-user state in the underlying data store for the page and users specified.
Top

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.


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

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft