Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET personalized


May 13, 2021 ASP.NET


Table of contents


Personalized

Web sites are designed for repeated visits by users. P ersonalization allows a website to remember user identities and other details of information, and it provides a personal environment for each user.

ASP.NET to personalize a website to meet the tastes and preferences of featured customers.

Understand the feature file

ASP.NET personalized service is based on the user's characteristic file. T he user characteristics file defines the information that the site requires from the user. F or example, name, age, address, date of birth and mobile phone number.

This information is defined in the application's web.config file and ASP.NET read and use it during the runtime. T his work is done by a personalized provider.

The user profile files contained in the user data are stored in the ASP.NET created by the default database. Y ou can create your own database to store feature files. F eature file data definitions are stored in profile web.config.

Example

Let's create a sample site where we want our app to remember user details such as name, address, date of birth, etc. A dd feature file details with the element in the web.config file.

<configuration>
<system.web>

<profile>
   <properties>
      <add name="Name" type ="String"/>
      <add name="Birthday" type ="System.DateTime"/>

      <group name="Address">
         <add name="Street"/>
         <add name="City"/>
         <add name="State"/>
         <add name="Zipcode"/>
      </group>

   </properties>
</profile>

</system.web>
</configuration>

When a feature file is defined in a web.config file, it can be used by the Profile property found in the current HttpContext and obtained through the page.

Add text box to get user input defined in the feature file, add a button to submit data:

ASP.NET personalized

Update Page_load to display feature file information:

using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
   protected void Page_Load(object sender, EventArgs e)
   {
      if (!this.IsPostBack)
      {
         ProfileCommon pc=this.Profile.GetProfile(Profile.UserName);

         if (pc != null)
         {
            this.txtname.Text = pc.Name;
            this.txtaddr.Text = pc.Address.Street;
            this.txtcity.Text = pc.Address.City;
            this.txtstate.Text = pc.Address.State;
            this.txtzip.Text = pc.Address.Zipcode;
            this.Calendar1.SelectedDate = pc.Birthday;
         }
      }
   }
}

To write the following handles to the submit button, the user data is stored in the feature file:

protected void btnsubmit_Click(object sender, EventArgs e)
{
   ProfileCommon pc=this.Profile.GetProfile(Profile.UserName);

   if (pc != null)
   {
      pc.Name = this.txtname.Text;
      pc.Address.Street = this.txtaddr.Text;
      pc.Address.City = this.txtcity.Text;
      pc.Address.State = this.txtstate.Text;
      pc.Address.Zipcode = this.txtzip.Text;
      pc.Birthday = this.Calendar1.SelectedDate;

      pc.Save();
   }
}

When the page is first executed, the user needs to enter information. H owever, the next user details will be loaded automatically.

The property of the element

In addition to the name and type properties we've already used, the element has other properties. T he following table shows some of these properties:

Property Describe
name The name of the property.
type The type defaults to string but it allows any full class name to be used as a data type.
serializeAS The format used when serializing this value.
readOnly Read-only feature file values cannot be changed, and this property defaults to false.
defaultValue A default value that is used if the feature file does not exist or if there is no information.
allowAnonymous A Boolean value that indicates whether this property can be used with anonymous files.
Provider Should be used to manage the feature file provider for this property.

Anonymous personalization

Anonymous personalization allows users to personalize their website before identifying themselves. F or example, Amazon.com allows users to add items to their shopping cart before logging in. T o enable this feature, the web.config file can be configured as follows:

<anonymousIdentification enabled ="true" cookieName=".ASPXANONYMOUSUSER"
   cookieTimeout="120000" cookiePath="/" cookieRequiresSSL="false"
   cookieSlidingExpiration="true" cookieprotection="Encryption"
   coolieless="UseDeviceProfile"/>