Understanding the Profile Object of ASP.NET Version 2.0 (Beta 1)
page 2 of 4
by Terry Voss
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 20829/ 70

Basic Knowledge

[Download Sample Project]

The System.Web.Profile namespace contains seventeen types:
 1) DefaultHttpProfile (inherits HttpProfileBase, provides untyped access to Profile properties)
 2) HttpProfileBase (provides untyped access to Profile properties)
 3) HttpProfileGroupBase (provides untyped access to group Profile properties)
 4) ProfileAuthenticationOption (enumeration: All, Anonymous, Authenticated)
 5) ProfileAutoSaveEventArgs (inherits EventArgs)
 6) ProfileEventArgs (inherits EventArgs)
 7) ProfileInfo (holds info about one user's profile)
 8) ProfileInfoCollection (holds info about all users' profiles)
 9) ProfileMigrateEventArgs (provides event data for the MigrateAnonymous event of the ProfileModule class)
10) ProfileModule (noninheritable/sealed; implements IHttpModule)
11) ProfileProvider (mustinherit)
12) ProfileProviderAttribute (noninheritable/sealed; inherits Attribute)
13) ProfileProviderCollection (usual collection members, count, add)
14) SettingsAllowAnonymousAttribute (noninheritable/sealed; inherits Attribute)
15) AccessProfileProvider (I couldn't successfully instantiate this; could be Microsoft-used class)
16) SqlProfileProvider (I couldn't successfully instantiate this; could be Microsoft-used class)
17) ProfileManager (allows management of profile info, like delete types, find types, get numbers of types, of profiles, most members are shared/static)

Use this important last class to manage either type of storage: MS Access or MS SQL Server, as it has many valuable methods. Two other valuable classes are the ProfileInfo and ProfileInfoCollection for reporting the user state status as you will see in later code samples.

If you create a new web project and immediately in the default.aspx file code-beside you type the following, you will get squiggles regarding Name member not existing for the Profile object.

Dim x as string = Profile.Name
With Visual Studio, go to the Website menu and choose the ASP.NET Configuration Option, choose Profile, choose Add Property, add a Name property, and Save. Now go back to your code. The squiggles are gone. This is because at least the following entries have been added to the web.config file.
<?xml version="1.0" encoding="utf-8"?>
<profile inherits="System.Web.Profile.HttpProfileBase, System.Web,
                   Version=2.0.3600.0, Culture=neutral,
    <add name="MyName" type="System.String" />

If you don't have Visual Studio, use the Profile tab of the Web Site Administration Tool (WAT) to manage how your site collects personal information about visitors. Profile properties represent data specific to a particular user. Using profile properties enables you to personalize your Web site for individual users. The address for this web application will be: http://localhost/AppFolderNameInWebsites/Webadmin.axd

The Profile property groups allow you to group related profile properties together within a collection. For example, you may choose to group the Title property along with other properties such as First, MiddleInitial, Middle, Last and Suffix in a property group called Name. In this example, you would set the value for the Suffix property with the following line of code:

Profile.Name.Suffix = "Junior"

Here is the associated web.config entries:

 <group name="Name"> 
   <property name="Title" type="System.String "/> 
   <property name="First" type="System.String "/> 
   <property name="Middle" type="System.String "/> 
   <property name="Initial" type="System.String "/> 
   <property name="Last" type="System.String "/> 
   <property name="Suffix" type="System.String "/> 
 <group name="Address"> 
   <property name="Street" type="System.String"/> 
   <property name="City" defaultValue="Redmond" type="System.String"/> 
   <property name="State" defaultValue="WA" type="System.String"/> 
   <property name="Zip" type="System.String"/> 

You can also create a custom type that you use as a Profile property. For example, you might have a class named ShoppingCart in a namespace called Sales that you can specify as a Profile property and can then associate with each user in your application. So ShoppingCart can be a collection of ItemOrder classes.

If you specify a custom type for your profile property, you must specify the fully-qualified class name for the type so that ASP.NET can instantiate the class when the application runs. If the ShoppingCart class is defined in your Code folder with a namespace of Sales, you would enter the following in the fully-qualified type name box under the custom data type option:


You can also enable tracking by a generated unique ID for anonymous users of your site. This ID is stored in a cookie on the user's computer.

View Entire Article

User Comments

Title: The shopping cart works great, but...   
Name: scott baldridge
Date: 2006-02-21 10:58:14 PM
I have a profile.shoppingCart working but am stuck with finding information on how to get the items from the cart to a SQL database. I can find no documentation or examples. Does anyone know how?
It's all easy to put the data into the cart but is useless if you can't get it to a database..

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-29 12:09:39 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search