Using Profiles : Introduction « Profile « ASP.NET Tutorial

The ASP.NET Framework provides an alternative to using cookies or Session state to store user information: the Profile object. 
The Profile object provides you with a strongly typed, persistent form of session state.

You create a Profile by defining a list of Profile properties in your application root web configuration file. 
The ASP.NET Framework dynamically compiles a class that contains these properties in the background.

The following web configuration file defines a Profile that contains three properties: firstName, lastName, and numberOfVisits.

File: Web.Config


      <add name="firstName" />
      <add name="lastName" />
      <add name="numberOfVisits" type="Int32" defaultValue="0" />
    <add name="xmlLastName" type="String" serializeAs="Xml"/>      


When you define a Profile property, you can use any of the following attributes:

name sets the name of the property.
type sets the type of the property. 

The type can be any custom type, including a custom component that you define in the App_Code folder.
The default type is string.

defaultValue is a default value for the property.

readOnly creates a read-only property. 
The default value is false.

serializeAs sets how a property is persisted into a static representation. 
Possible values are Binary, ProviderSpecific, String, and Xml. 
The default value is ProviderSpecific.

allowAnonymous allows anonymous users to read and set the property. 
The default value is false.

provider associates the property with a particular Profile provider.

customProviderData passes custom data to a Profile provider.

File: ShowProfile.aspx

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

    void Page_PreRender()
        lblFirstname.Text = Profile.firstName;
        lblLastName.Text = Profile.lastName;

        lblNumberOfVisits.Text = Profile.numberOfVisits.ToString();
    protected void btnUpdate_Click(object sender, EventArgs e)
        Profile.firstName = txtNewFirstName.Text;
        Profile.lastName = txtNewLastName.Text;
<html xmlns="" >
<head id="Head1" runat="server">
    <title>Show Profile</title>
    <form id="form1" runat="server">

    First Name:
        Runat="server" />
    <br /><br />
    Last Name:
        Runat="server" />
    <br /><br />
    Number of Visits:
        Runat="server" />

    <hr />

        Text="New First Name:"
        Runat="server" />
        Runat="server" />
    <br /><br />
        Text="New Last Name:"
        Runat="server" />
        Runat="server" />
    <br /><br />
        Text="Update Profile"
        Runat="server" />


15.5.1.Using Profiles
15.5.2.Get / set profile data defined in Web.config
15.5.3.Get / set user-defined object to profile
15.5.4.Inheriting a Profile from a Custom Class
15.5.5.Creating Complex Profile Properties
15.5.6.Making Personalization Properties Read-Only
15.5.7.Defining default values for personalization properties
15.5.8.Working with the automaticSaveEnabled attribute