-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion
Profile Provider
ASP.NET 2.0 is a compelling platform for most Web sites. The inclusion of many
of the basic facilities that most Web sites will need like the ability to have
members, keep profile information on those members and use role-based
authorization, makes ASP.NET 2.0 an easy decision for new development.
Introduction
Probably the most compelling of these system is the profile system which allows
you to keep data about visitors to your Web site (anonymous or not). The
default profiling system in ASP.NET 2.0 fits into many Web site use-cases, but
not all. Luckily, none of these systems in ASP.NET 2.0 require you to meet
their specific feature set. ASP.NET 2.0 uses something called a Provider Model
to allow extension or replacement of their implementation to fit into website
specific use-cases. As a developer, this means that if it doesn't fit, you
don't have to throw the baby out with the bathwater. As an example, let's look
at how the Profile system works in ASP.NET 2.0.
The Profile Provider
The ASP.NET team implemented the profile management features using a provider
model. A base ProfileProvider class defines the interface, or contract, that
all profile providers must implement. ASP.NET 2.0 ships with an implementation
of the ProfileProvider that uses SQL Server the SqlProfileProvider class.
SqlProfileProvider implements the ProfileProvider methods (like
FindProfilesByUserName) by executing stored procedures in SQL Server.
The provider model is extensible. If you dont want to use SQL Server, but want
to use an XML file or a different relational database engine, you can define
your own class derived from the ProfileProvider class and implement all the
Profile features using a different data store. The beauty of the provider model
is how you can plug your own implementation of a feature into the system, and
the runtime and application continue to work without knowing the details of the
implementation. Later in the article, we will discuss the provider
configuration. For now, lets take a closer look at configuring Profile
properties in web.config.
Configuring Profile Properties
Lets extend our Profile settings with the following web.config.
<profile >
<properties>
<add name="Name" allowAnonymous="true" />
<add name="Age" allowAnonymous="true" type="System.Int16"/>
<group name="UI">
<add name="MasterPage" defaultValue="layout1.master"/>
<add name="Theme" defaultValue="Red"/>
</group>
</properties>
</profile>
First, Profile properties use the String type by default. We can change the
default with the type attribute, as we do with the Age property (typed as
Int16). We can define a default value for a profile property with the
defaultValue attribute. The provider will use the default value when a property
value does not yet exist in the data store.
By default, Profile properties are only available for authenticated users. If
we want a property to be available for an anonymous user, we need to add
allowAnonymous=true to the property. Without the attribute, the runtime will
throw an exception if the current user is anonymous and we write to the
property. At some point an anonymous user might login and become an
authenticated user. After a user authenticates, their Profile changes, because
the Profile system keys Profile information by username.
We can create a hierarchy of profile properties using the group element.
Grouping allows us to categorize properties, which can be helpful when there
are a large number of profile properties. We can specify more than one property
group, but we cannot nest a group beneath another group element
Profile Base Class
A Profile class has to derive from ProfileBase. The public properties in the
CustomProfile class forward calls to the ProfileBase indexer ([] in C#, () in
VB). The base class will interact with the Profile provider to retrieve the
values we need. Notice the class even uses a generic collection to store a list
of all the users pets. To use the class, we just need to reconfigure our
profile settings in web.config and use the inherits attribute
Profile Manager Class
Discussion of Profiles would be incomplete without mentioning the
ProfileManager class. The ProfileManager class is useful for managing profiles.
Since the class is a static class, all the members are available to call
without creating an instance of the class. The class is useful for managing
profiles (ProfileManager.DeleteInactiveProfiles, for example), and for
reporting on profiles. The GetAllProfiles method, for instance, includes an
overload which accepts paging parameters (pageSize, pageIndex). The
DeleteInactiveProfiles method will clean up profile records that have not been
touched since a certain date.
Hopefully this article has demonstrated the flexibility of the ASP.NET Profile
features. The ProfileProvider and company will save us time in developing a
framework to store user specific data between visits. Use this feature to build
a shopping cart, personalize your web application, and more.
Swapnil (Swaps)
http://swapsnet.spaces.live.com/
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]