120 likes | 252 Views
Personalizing Web Sites. Nasrullah. Understanding Profile. The ASP.NET application service that enables you to store and retrieve information about users to your site. Continued.
E N D
Personalizing Web Sites Nasrullah
Understanding Profile • The ASP.NET application service that enables you to store and retrieve information about users to your site
Continued You access the information in a user’s profile through a clean API with virtually no code. All you need to do is define the information you want to keep track of in the central web.config file and the Profile feature takes care of the rest. All interaction with the database to retrieve or store profile information in the database is handled automatically for you.
Enabling profile • 1. Define the information you want to store for a user in the web.config file. Based on this information, the ASP.NET runtime generates and compiles a class for you on the fly that gives you access to the properties you defined. It then dynamically adds a property called Profile to the pages in your web site, so you can easily access it from every page in your site. 2. In your application you program directly to this generated class to get and store the profile information for the current user.
Configuring profile • Because data about the logged-in user is stored in a cookie by default, your users need to have browsers that support cookies for the ASP.NET Profile feature to work correctly.
Configurnig a profile You define a profile for your web site in the web.config file by creating a <profile> element as a direct child of the <system.web> element. Between the <profile> tags you need to create a <properties> element that is used to define the properties you want to expose from your Profile object. Two types of properties exist: simple properties and complex properties, referred to as profile groups.
Configuring a profile <system.web> ... <profile> <properties> <add name=”FirstName” allowAnonymous=”True” /> <add name=”DateOfBirth” type=”System.DateTime” /> </properties> </profile
Configuring profile • When you define profile properties in web.config, the ASP.NET runtime creates a class for you in the background. This class, called ProfileCommon,givesyou access to the strongly typed properties such as FirstName, LastName, and FavoriteGenres. The ProfileCommon class is then made accessible to the Page through its Profile property
Reading from profile • Reading from the profile is just as easy; all you need to do is access one of its properties FirstName.Text = Profile.FirstName; PostalAddressStreet.Text= Profile.PostalAddress.Street;
ASP.NET Profile provider • The ASP.NET provider responsible for storing and retrieving profile related data
Anonymous identification • The ASP.NET feature that enables you to track users to your site, even if they haven’t signed up for an account or are not logged in