Personalization in ASP.Net:
Web sites are prepared for repeated visits from the users. Personalization allows a site to remember its user and his/her information details and shows an individualistic environment to every user.
ASP.Net gives services for personalizing a web site to suit a specific client's preference and taste.
Understanding Profiles:
ASP.Net personalization service is lied on user profile. User profile describes the kind of information about the user that the site will require, for example, name, address, age, date of birth, phone number etc.
This information is given in the web.config file of the application and ASP.Net runtime uses and reads it. This job is completed by the personalization providers.
The user profiles obtained from user data is saved in a default database build by ASP.Net. You may prepare your own database for saving profiles. The profile data definition is saved in the configuration file web.config.
Example:
Let us make a sample site, where we want our application to remember user details like address, name, date of birth etc. Include the profile details in the web.config file within the <system.web> element.
<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 the profile is described in the web.config file, the profile could be used through the Profile property searched in the current HttpContext and also available via page.
Include the text boxes to take the user input as given in the profile and add a button for submitting the data:
![2461_personalize.png](https://www.expertsmind.com/CMSImages/2461_personalize.png)
Update Page_load to show profile 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;
}
}
}
}
|
Write the subsequent handler for the Submit button, for saving the user data into the profile:
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();
}
}
|
Observe: When the page is executed for the first time, the user information require to be entered. However, next time the user details would be automatically loaded.
Attributes for the <add> Element
Apart from the type and name attributes that we have used, there are other attributes to the <add> element. Following table explains some of these attributes:
Attributes
|
Description
|
name
|
The name of the property.
|
type
|
By default the type is string but it gives any fully qualified class name as data type.
|
serializeAs
|
The format to use when serializing this value.
|
readOnly
|
A read only profile value cannot be modified, by default this property is false.
|
defaultValue
|
A default value that will be used if the profile does not be present or does not have information.
|
allowAnonymous
|
A Boolean value showing whether this property may be used with the anonymous profiles.
|
Provider
|
The profiles provider that could be used to organize just this property.
|
Anonymous Personalization:
Anonymous personalization gives the user to customize the site before identifying themselves. For example, Amazon.com provides the user to include items in the shopping cart before they log in. To activate this feature, the web.config file should be configured as:
<anonymousIdentification enabled ="true"
cookieName=".ASPXANONYMOUSUSER"
cookieTimeout="120000"
cookiePath="/"
cookieRequiresSSL="false"
cookieSlidingExpiration="true"
cookieprotection="Encryption"
coolieless="UseDeviceProfile"/>
|
Email based ASP.Net assignment help - homework help at Expertsmind
Are you searching ASP.Net expert for help with Personalization in ASP.Net questions? Personalization in ASP.Net topic is not easier to learn without external help? We at www.expertsmind.com offer finest service of ASP.Net assignment help and ASP.Net homework help. Live tutors are available for 24x7 hours helping students in their Personalization in ASP.Net related problems. Computer science programming assignments help making life easy for students. We provide step by step Personalization in ASP.Net question's answers with 100% plagiarism free content. We prepare quality content and notes for Personalization in ASP.Net topic under ASP.Net theory and study material. These are avail for subscribed users and they can get advantages anytime.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving ASP.Net queries in excels and word format.
- Best tutoring assistance 24x7 hours