ProfileBase Constructor ()


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

Creates an instance of the ProfileBase class.

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

public ProfileBase()

Exception Condition

The enabled attribute of the section of the Web.config file is false.


A property type specified in the section of the Web.config file could not be created.


The allowAnonymous attribute for a property in the section of the Web.config file is set to true and the enabled attribute of the element is set to false.


The serializeAs attribute for a property in the section of the Web.config file is set to Binary and the IsSerializable property of the specified type returns false.


The name of a provider specified using the provider attribute of a profile property could not be found in the Providers collection.


The type specified for a profile property could not be found.


A profile property was specified with a name that matches a property name on the base class specified in the inherits attribute of the section.

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.


The base class used to generate the class stored in the Profile property can be overridden using the inherits attribute of the section of the configuration file. In this case you would specify a custom class that inherits from the ProfileBase base class.

This constructor is not intended to be used from application code. To create an instance of a user profile, use the Create method.

The following Web.config file 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.

       <add name="SqlServices" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=aspnetdb;" />

   <anonymousIdentification enabled="true" />

   <profile defaultProvider="SqlProvider" >
         type="System.Web.Profile.SqlProfileProvider" />

       <add name="ZipCode" allowAnonymous="true" />
       <add name="RecentSearchList"
            allowAnonymous="true" />

The following ASP.NET page reads and sets the ZipCode property specified for the user profile.

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#" %>
<!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" />


.NET Framework
Available since 2.0
Return to top