The many wonders of the Profile Object

14 October, 2006 (17:34) | .NET | By: Thomas

Recently I had a conversation with the owner of a e-commerce web site. He expressed some of his frustrations with the structure of many e-commerce sites, including his own,  by saying very simply and succinctly “ Give me Amazon.com. Give me a way for a customer to purchase items by NOT asking them to provide a bunch of personal details  until the very last minute. I don’t want to log in,or register on a site just to see the products. Thats like having an ID check in every store of a mall. Thats nuts! ” 

I can understand this customers frustrations completely. Amazon seems to be the ecommerce standard. Luckily, ASP.NET 2.0 provides a built-in mechanism for shopping without registration and much more. It is called the Profile Object. I wonder how many developers when reading up on Profiles simply looked at them as a way top store some user preferences for a site. Things like a color scheme the user picked or a layout.That was my initial take on this object as well. “Oh yes… personalization… been there done that..”.  If I had not stopped for a minute I would have completely overlooked the most important aspects of Profile that also happen to apply to this very situation here.

One of the strongest features of the Profile object is its ability to deal with anonymous users. Most sites and most technologies have an easy time in dealing with users that have been authenticated and are logged in. But what about the needs of the shop keeper mentioned above and anonymous users? Let anyone come along, add some stuff to shopping cart and remember the cart if the user returns. Don’t ask for personal details until the user clicks “Checkout”. Sounds like Amazon right? If you are coming form Java / JSP or other non Microsoft technologies you maybe tempted to reach for the trusty session object. And yes that would certainly be a solution. But Profile brings additional capabilities to the table that do make it a viable alternative, if not the tool of choice here.

Without getting into too much detail here, Profile is a combination of config file values, a framework base class, a provider and a derived class. For further details see the bottom of this post. Profile works for anonymous users by creating a unique id automatically and storing that id on the users machine. No its not a SessionId.  Call it a profile cookie if you want. This cookie can then contain any number of things you would like to remember about this anonymous user – including a serialized copy of a shopping cart if needed. So there you have it. All built into ASP.NET and ready to go. Of course there are various nitty gritty details that need to be addressed when using anonymous profiles. What happens when the user checks out and actually registers? Again, its been thought of. The Profile system comes with a class called ProfileManager that raises an event – I believe its called MigrateAnonymous – that can be intercepted in you global.asax and you can write code to specifically move shopping cart data as needed into the authenticated Profile (assuming the user does register on checkout).

So thats is the answer for our beleaguered ecommerce shop keeper. But there is more. Profiles can be used to track user preferences and clicks. Again, there are tons of ways of doing this for logged in, authenticated users, but conceptually its tough to apply some of these techniques to anonymous users. Profile, via the same cookie mechanisms, allows you to track the behavior of an anonymous user on a site. Why? Because you want to dynamically adjust the advertisements and special offers that a person sees. For example, by checking some counters you have stored in the anonymous users profile you can determine this person has viewed more Baseball related pages as opposed to Automotive pages. Knowing that can allow you to adjust the offers and ads this anonymous user is shown, thus increasing your chances for a sale or a click on another item.

All in all, I think any developer coming to .NET from one of the other programming environments should spend a little time with Profile. Its a useful thing.

Some reference material:
K.Scott Allan has a great write up on the technical details of Profile.

 

Write a comment

You need to login to post comments!