ProfileManager Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Manages user profile data and settings.

Namespace:   System.Web.Profile
Assembly:  System.Web (in System.Web.dll)


public static class ProfileManager


Gets or sets the name of the application for which to store and retrieve profile information.


Gets a value indicating whether the user profile will be automatically saved at the end of the execution of an ASP.NET page.


Gets a value indicating whether the user profile is enabled for the application.


Gets a reference to the default profile provider for the application.


Gets a collection of the profile providers for the ASP.NET application.


Adds a profile property programmatically.

System_CAPS_pubmethodSystem_CAPS_staticDeleteInactiveProfiles(ProfileAuthenticationOption, DateTime)

Deletes user profile data for which the last activity date and time occurred before the specified date and time.


Deletes the profile for the specified user name from the data source.


Deletes profile properties and information from the data source for the supplied list of profiles.


Deletes profile properties and information for the supplied list of user names.

System_CAPS_pubmethodSystem_CAPS_staticFindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime)

Retrieves profile information for all profiles in which the last activity date occurred on or before the specified date and time and the user name for the profile matches the specified name.

System_CAPS_pubmethodSystem_CAPS_staticFindInactiveProfilesByUserName(ProfileAuthenticationOption, String, DateTime, Int32, Int32, Int32)

Retrieves profile information in pages of data for profiles in which the last activity date occurred on or before the specified date and time and the user name for the profile matches the specified name.

System_CAPS_pubmethodSystem_CAPS_staticFindProfilesByUserName(ProfileAuthenticationOption, String)

Retrieves all profile information for profiles in which the user name matches the specified name.

System_CAPS_pubmethodSystem_CAPS_staticFindProfilesByUserName(ProfileAuthenticationOption, String, Int32, Int32, Int32)

Retrieves profile information in pages of data for profiles in which the user name matches the specified name.

System_CAPS_pubmethodSystem_CAPS_staticGetAllInactiveProfiles(ProfileAuthenticationOption, DateTime)

Retrieves all user profile data for profiles in which the last activity date occurred on or before the specified date and time.

System_CAPS_pubmethodSystem_CAPS_staticGetAllInactiveProfiles(ProfileAuthenticationOption, DateTime, Int32, Int32, Int32)

Retrieves a page of ProfileInfo objects for user profiles in which the last activity date occurred on or before the specified date and time.


Retrieves user profile data for profiles in the data source.

System_CAPS_pubmethodSystem_CAPS_staticGetAllProfiles(ProfileAuthenticationOption, Int32, Int32, Int32)

Retrieves pages of user profile data.

System_CAPS_pubmethodSystem_CAPS_staticGetNumberOfInactiveProfiles(ProfileAuthenticationOption, DateTime)

Gets the number of profiles in which the last activity date occurred on or before the specified date.


Gets the number of profiles in the data source.

The ASP.NET profile is used to store and retrieve user settings in a data source such as a database. The user profile is accessed using the Profile property of the current HttpContext. Profile information and property values are managed using a profile provider.

The ProfileManager class is used to manage profile settings, search for user profiles, and delete user profiles that are no longer in use. The ProfileManager class provides static methods and properties that can be accessed by referencing the ProfileManager class in your application code. For an example, see the Example section in this topic and additional examples in the topics for members of the ProfileManager class.

By default, the user profile is disabled for all ASP.NET applications. To enable the user profile, set the enabled attribute of the configuration element to true, as shown in the following example.

    <profile enabled="true" />

For more information about the user profile, see ASP.NET Profile Properties Overview.

A profile provider is used to store and retrieve properties in the user profile. The .NET Framework includes a SqlProfileProvider class that stores user profile properties in a SQL Server database. A SqlProfileProvider instance named AspNetSqlProvider is specified in the machine configuration as the default profile provider. The AspNetSqlProvider instance connects to the SQL Server database on the local Web server. You can specify a SqlProfileProvider that connects to another SQL Server as the default profile provider by using the configuration element and the defaultProvider attribute of the configuration element, as shown in the following example.

    <add name="SqlServices" connectionString=
      "Data Source=MySqlServer;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />
    <profile defaultProvider="SqlProvider">
        <clear />
        <add name="SqlProvider"
          applicationName="MyApplication" />

The following code example shows an ASP.NET page that uses the ProfileManager class to manage inactive profiles.

System_CAPS_security Security Note

This example contains 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.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Profile" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

int pageSize = 5;
int totalProfiles;
int totalPages;
int currentPage = 1;

ProfileAuthenticationOption authOption;
int inactiveDays = 120;
int deletedProfiles = 0;

public void Page_Load()
  DeletedMessage.Text = "";

  authOption = GetAuthenticationOption();

  if (!IsPostBack)
    InactiveDaysTextBox.Text = inactiveDays.ToString();

    inactiveDays = Convert.ToInt32(InactiveDaysTextBox.Text);

public void ProfileGrid_Delete(object sender, GridViewCommandEventArgs args)
  // Retrieve user name selected.

  int index = Convert.ToInt32(args.CommandArgument);

  string username = ProfileGrid.Rows[index].Cells[0].Text;

  ProfileManager.DeleteProfiles(new string[] {username});

  DeletedMessage.Text = "1 profile deleted.";

  // Refresh profile list.

  currentPage = Convert.ToInt32(CurrentPageLabel.Text);

private void GetProfiles()
  ProfileGrid.DataSource = ProfileManager.GetAllInactiveProfiles(authOption,
                               DateTime.Now.Subtract(new TimeSpan(inactiveDays, 0, 0, 0)),
                               currentPage - 1, pageSize, out totalProfiles);

  TotalProfilesLabel.Text = totalProfiles.ToString();

  totalPages = ((totalProfiles - 1) / pageSize) + 1;

  // Ensure that we do not navigate past the last page of Profiles.

  if (currentPage > totalPages)
    currentPage = totalPages;

  CurrentPageLabel.Text = currentPage.ToString();
  TotalPagesLabel.Text = totalPages.ToString();

  if (currentPage == totalPages)
    NextButton.Visible = false;
    NextButton.Visible = true;

  if (currentPage == 1)
    PreviousButton.Visible = false;
    PreviousButton.Visible = true;

  if (totalProfiles <= 0)
    NavigationPanel.Visible = false;
    NavigationPanel.Visible = true;

public void NextButton_OnClick(object sender, EventArgs args)
  currentPage = Convert.ToInt32(CurrentPageLabel.Text);

public void PreviousButton_OnClick(object sender, EventArgs args)
  currentPage = Convert.ToInt32(CurrentPageLabel.Text);

public void ModifyInactiveDaysButton_OnClick(object sender, EventArgs args)

public void AuthenticationOptionListBox_OnSelectedIndexChanged(object sender, EventArgs args)
  authOption = GetAuthenticationOption();

private ProfileAuthenticationOption GetAuthenticationOption()
  if (AuthenticationOptionListBox.SelectedItem != null)
    switch (AuthenticationOptionListBox.SelectedItem.Value)
      case "Anonymous":
        return ProfileAuthenticationOption.Anonymous;
      case "Authenticated":
        return ProfileAuthenticationOption.Authenticated;
        return ProfileAuthenticationOption.All;

  return ProfileAuthenticationOption.All;

public void DeleteAllInactiveButton_OnClick(object sender, EventArgs args)
  deletedProfiles = ProfileManager.DeleteInactiveProfiles(authOption, 
                        DateTime.Now.Subtract(new TimeSpan(inactiveDays, 0, 0 ,0)));
  DeletedMessage.Text = deletedProfiles.ToString() + " profiles deleted.";

<html xmlns="" >
<title>Sample: Find Profiles</title>

<form id="form1" runat="server">
  <h3>Profile List</h3>

  <table border="0" cellpadding="3" cellspacing="3">
      <td valign="top">Authentication Option</td>
      <td valign="top"><asp:ListBox id="AuthenticationOptionListBox" rows="3" runat="Server"
                         <asp:ListItem value="All" selected="True">All</asp:ListItem>
                         <asp:ListItem value="Authenticated">Authenticated</asp:ListItem>
                         <asp:ListItem value="Anonymous">Anonymous</asp:ListItem>
      <td valign="top" style="width:160">
        Number of Days for Profile to be considered "inactive"</td>
      <td valign="top" style="width:200">
        <asp:TextBox id="InactiveDaysTextBox" runat="Server" MaxLength="3" Columns="3" />
        <asp:Button id="ModifyInactiveDaysButton" runat="server" Text="Refresh Results" 
           OnClick="ModifyInactiveDaysButton_OnClick" /><br />
        <asp:Button id="DeleteAllInactiveButton" runat="Server"
           Text="Delete All Inactive Profiles" OnClick="DeleteAllInactiveButton_OnClick" />
      <td valign="top">
        <asp:RequiredFieldValidator id="InactiveDaysRequiredValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ErrorMessage="Required" />
        <asp:RegularExpressionValidator id="InactiveDaysValidator" runat="server"
           ControlToValidate="InactiveDaysTextBox" ForeColor="red"
           Display="Static" ValidationExpression="[0-9]*" 
           ErrorMessage="Inactive Days must be a whole number less than 1000 (e.g. 30, 120)" />
      <td><asp:Label id="DeletedMessage" runat="server" /></td>
      <td><asp:Label id="TotalProfilesLabel" runat="server" /> inactive profiles found.</td>

    <asp:Panel id="NavigationPanel" Visible="false" runat="server">
    <table border="0" cellpadding="3" cellspacing="3">
        <td style="width:100">Page <asp:Label id="CurrentPageLabel" runat="server" />
            of <asp:Label id="TotalPagesLabel" runat="server" /></td>
        <td style="width:60"><asp:LinkButton id="PreviousButton" Text="< Prev"
                            OnClick="PreviousButton_OnClick" runat="server" /></td>
        <td style="width:60"><asp:LinkButton id="NextButton" Text="Next >"
                            OnClick="NextButton_OnClick" runat="server" /></td>

  <asp:GridView id="ProfileGrid" runat="server" AutoGenerateColumns="false"
                CellPadding="2" CellSpacing="1" Gridlines="None">
    <HeaderStyle BackColor="darkblue" ForeColor="white" />
      <asp:BoundField HeaderText="User Name" DataField="Username" />
      <asp:BoundField HeaderText="Is Anonymous" DataField="IsAnonymous" />
      <asp:BoundField HeaderText="Last Updated" DataField="LastUpdatedDate" />
      <asp:BoundField HeaderText="Last Activity" DataField="LastActivityDate" />
      <asp:ButtonField HeaderText="Action" Text="Delete" ButtonType="Link" />



.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