ProfileBase Class

ProfileBase Class


Provides untyped access to profile property values and information.

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

public class ProfileBase : SettingsBase


Creates an instance of the ProfileBase class.


Gets the associated settings context.(Inherited from SettingsBase.)


Gets a value indicating whether the user profile is for an anonymous user.


Gets a value indicating whether any of the profile properties have been modified.


Gets a value indicating whether access to the object is synchronized (thread safe). (Inherited from SettingsBase.)


Gets or sets a profile property value indexed by the property name.(Overrides SettingsBase.Item[String].)


Gets the most recent date and time that the profile was read or modified.


Gets the most recent date and time that the profile was modified.


Gets a collection of SettingsProperty objects for each property in the profile.


Gets a collection of settings property values.(Inherited from SettingsBase.)


Gets a collection of settings providers.(Inherited from SettingsBase.)


Gets the user name for the profile.


Used by ASP.NET to create an instance of a profile for the specified user name.

System_CAPS_pubmethodSystem_CAPS_staticCreate(String, Boolean)

Used by ASP.NET to create an instance of a profile for the specified user name. Takes a parameter indicating whether the user is authenticated or anonymous.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets a group of properties identified by a group name.


Gets the value of a profile property.


Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitialize(SettingsContext, SettingsPropertyCollection, SettingsProviderCollection)

Initializes internal properties used by SettingsBase object.(Inherited from SettingsBase.)

System_CAPS_pubmethodInitialize(String, Boolean)

Initializes the profile property values and information for the current user.


Creates a shallow copy of the current Object.(Inherited from Object.)


Updates the profile data source with changed profile property values.(Overrides SettingsBase.Save().)

System_CAPS_pubmethodSetPropertyValue(String, Object)

Sets the value of a profile property.


Returns a string that represents the current object.(Inherited from Object.)

ASP.NET uses the ProfileBase class to create the class used for the user profile. When an application that has the user profile enabled is started, ASP.NET creates a new class of type ProfileCommon, which inherits from the ProfileBase class. Strongly typed accessors are added to the ProfileCommon class for each property defined in the configuration section. The strongly typed accessors of the ProfileCommon class call the GetPropertyValue and SetPropertyValue methods of the ProfileBase base class to retrieve and set profile property values, respectively. An instance of the ProfileCommon class is set as the value of the Profile property for the ASP.NET application.

To create an instance of a user profile in an ASP.NET application, it is recommended that you use the Create method.

Notes to Inheritors:

You can create a custom profile implementation that inherits from the ProfileBase abstract class and defines properties for the user profile that are not specified in the configuration element. You can specify a custom user-profile type in the Web.config file with the inherits attribute of the configuration element, as shown in the following example. The code for the EmployeeProfile class is included in the Example section of this topic.

<profile inherits="Samples.AspNet.Profile.EmployeeProfile"
    <clear />
      description="SQL Profile Provider for Sample"/> 
      description="SQL Profile Provider for Employee Info"/> 

    <add name="GarmentSize" />

The following code example shows a Web.config file that specifies a user profile that contains a ZipCode property of type string and a RecentSearchList property of type StringCollection. The generated Profile property of the current HttpContext will have strongly typed accessors for each of the specified properties.

    <anonymousIdentification enabled="true" />

    <profile enabled="true" defaultProvider="SqlProvider" >
        <add name="ZipCode" allowAnonymous="true" />
        <add name="RecentSearchList"
          allowAnonymous="true" />

The following code example shows an ASP.NET page that reads and sets the ZipCode property specified for the user profile. Before attempting to run this code, set the provider to the default AspNetSqlProvider in the ASP.NET configuration settings for the Web site.

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

public void Page_PreRender()
  if (Profile.ZipCode == null)
    PersonalizePanel.Visible = false;
    GetZipCodePanel.Visible = true;
    ZipCodeLabel.Text = Profile.ZipCode;

    // Get personalized information for zip code here.

    PersonalizePanel.Visible = true;
    GetZipCodePanel.Visible = false;

public void ChangeZipCode_OnClick(object sender, EventArgs args)
  ZipCodeTextBox.Text = Profile.ZipCode;
  Profile.ZipCode = null;

  PersonalizePanel.Visible = false;
  GetZipCodePanel.Visible = true;

public void EnterZipCode_OnClick(object sender, EventArgs args)
  Profile.ZipCode = ZipCodeTextBox.Text;

<html xmlns="" >
<title>Home Page</title>

<form id="form1" runat="server">
  <table border="1" cellpadding="2" cellspacing="2">
        <asp:Panel id="PersonalizePanel" runat="Server" Visible="False">
          Information for Zip Code: <asp:Label id="ZipCodeLabel" Runat="Server" /><br />
          <!-- Information for Zip Code here. -->
          <br />
          <asp:LinkButton id="ChangeZipCodeButton" Runat="Server" Text="Change Your Zip Code"
                          OnClick="ChangeZipCode_OnClick" />
        <asp:Panel id="GetZipCodePanel" runat="Server" Visible="False">
          You can personalize this page by entering your Zip Code: 
          <asp:TextBox id="ZipCodeTextBox" Columns="5" MaxLength="5" runat="Server" />
          <asp:LinkButton id="EnterZipCodeButton" Runat="Server" Text="Go"
                          OnClick="EnterZipCode_OnClick" />


The following code example defines a class that inherits from the ProfileBase class to create a custom profile. The type of the custom profile is specified in the inherits attribute of the configuration element in the Web.config file for an application.

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.

using System;
using System.Web.Profile;

namespace Samples.AspNet.Profile
  public class EmployeeProfile : ProfileBase
    public string Department
      get { return base["EmployeeDepartment"].ToString(); }
      set { base["EmployeeDepartment"] = value; }

    public EmployeeInfo Details
      get { return (EmployeeInfo)base["EmployeeInfo"]; }
      set { base["EmployeeInfo"] = value; }


  public class EmployeeInfo
    public string Name;
    public string Address;
    public string Phone;
    public string EmergencyContactName;
    public string EmergencyContactAddress;
    public string EmergencyContactPhone;

.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
© 2015 Microsoft