The ASP.NET Framework provides an alternative to using cookies or Session state to store user information as a Profile object. When a user visits your site, you can use the information you have stored to present the user with a personalized version of your Web application. Personalizing an application requires a number of elements: you must store the information using a unique user identifier, be able to recognize users when they visit again, and then fetch the user information as needed. To simplify your applications, you can use the ASP.NET profile feature, which can perform all of these tasks for you.

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.


File: Web.Config
                            <add name="Name"/>
                           <add name="Age" type="System.Int16" />
                           <add name="numberOfVisits" type="Int32" defaultValue="0" />

File: ShowProfile.aspx
                <html xmlns="">
    <head runat="server">
    <script runat="server">
              protected void Page_Load(object sender, EventArgs e)
                     if (!Page.IsPostBack)
                           nameTextBox.Text = Profile.Name;
                           ageTextBox.Text = Profile.Age.ToString();
                           lblNoOfVisit.Text = Profile.numberOfVisits.ToString();
              protected void updateProfileButton_Click(object sender, EventArgs e)
                           Profile.Name = nameTextBox.Text;
                           Profile.Age = Int16.Parse(ageTextBox.Text);
              <form id="form1" runat="server">
              <hr />
                     <asp:TextBox runat="server" ID="nameTextBox" /><br />
                     <asp:TextBox runat="server" ID="ageTextBox" /><br />
                     <asp:Label runat="server" ID="lblNoOfVisit"></asp:Label><br />
                     <asp:Button runat="server" ID="updateProfileButton" Text="Save  
                                Preferences" OnClick="updateProfileButton_Click" />

The above code creates profile by using web.config file and stores user information in profile object and also display’s the information of user by using profile object.

  Modified On Sep-18-2014 01:23:58 PM

Leave Comment