1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Personalization in ASP.NET

Discussion in 'ASP.NET' started by MinalS, Sep 3, 2015.

  1. A user profile is a collection of information user needs to be stored. The configuration file contains all the details. The Profile property is used for referencing the user information. The schema information is present in the configuration. A class is created which can be accessed from the property.

    User can create a database for storing the data. The profile data is saved in the web.config file. The Profile Manager provides support for the administration of the profiles. The manager can perform search for the profile information, authenticate users, profile modifications performed, modifying individual profiles by deleting profiles dependent on the changes.

    Example to demonstrate the use of profiles in an application
    1. Create an ASP.NET web application in Visual Studio
    2. Add text boxes and labels on the design view of the web form
    3. In the web.config file, add the code inside the <system.web> element.

              <add name ="StudName" type="String"/>
              <group name="Information">
                  <add name="StudID" />
                  <add name="Marks" />
                  <add name ="Percentage" />
    4. In the code behind file, add the following code
      using System.Web;
      using System.Data;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.Controls;
      using System.Web.UI.WebControls.WebParts;
      public partial class _Default: System.Web.UI.Page
          protected void Page_Load(object sender, EventArgs e)
              if ( !this.IsPostBack)
                  ProfileCommon profile = this.Profile.GetProfile(Profile.UserName);
                  if( profile! = null )
                      this.txt1.Text = profile.StudName;
                      this.txt2.Text = profile.Information.StudID;
                      this.txt3.Text = profile.Information.Marks;
                      this.txt4.Text = profile.Information.Percentage;
    5. Add a save button on the web form and on the event handler add the following code
      protected void btnsave_Click(object sender, EventArgs e)
          ProfileCommon profile = this.Profile.GetProfile(Profile.UserName);
          if ( profile != null )
              profile.StudName = this.txt1.Text;
              profile.Information.StudID = this.txt2.Text;
              profile.Information.Marks = this.txt3.Text;
              profile.Information.Percentage = this.txt4.Text;
    When the page is compiled and executed, all the contents are inserted by the user. Later, the details can be easily accessed.

    Attributes for <add> element

    There are various attributes provided by the <add> element for accessing the values. They are as listed below.
    1. type: User can add the fully qualified class name as a data type.
    2. name: It is used for adding the name to the specific property
    3. readOnly: User cannot modified the property once declared as readOnly. It is a Boolean attribute. It has false as its default value
    4. defaultValue: If the profile does not contain any value, it provides one. It is a string attribute.
    5. Provider: The profile provider is provided which is useful for accessing the values from the property
    6. allowAnonymous: Decides whether the property can be used with the anonymous profiles.
    7. serializeAs: The format is useful for string serialization
    The general format for the <add> element is shown below.
        name = "property name"
        type = "qualified reference type"
        provider = "name of the provider"
        serializeAs = "Xml | Binary | String | ProviderSpecific"
        allowAnonymous = "true | false"
        readOnly = "true | false"
        defaultValue = "property value"
        customProviderData = "custom profile provider"
    Anonymous personalization

    In ASP.NET, personalization helps user to enable the personalization features. It is useful if the site needs every person to register. The anonymous personalization is off by default in any application. It is because the resources of the database are accessed.

    User can easily enable the anonymous personalization by modifying the code in the configuration file. The <anonymousIdentification> element is used for enabling the personalization.

    In the configuration file, under the <system.web> node, add the <anonymousIdentification> element as shown below.

            <anonymousIdentification enabled = "true" />
    The anonymous identifiers can be saved using the cookies. User can easily modify the method.

            <anonymousIdentification enabled = "true" cookieless = "UseUri" />
    The other options that can be used for the cookie are listed below.
    1. UseDeviceProfile: The identifier for the device is configured
    2. UseCookies: It is used as the default value for the cookies. The application considers it as the value
    3. AutoDetect: It is decided by the engine whether the cookie or profile should be used
    4. UseUri: The cookie is not saved on the user machine. It provides a unique identifier which is managed by the page URL.

Share This Page