Implementation
of Profiles:
To use profiles, you first enable profiles by
modifying the configuration file for your ASP.NET Web application. As part of
the configuration, you specify a profile provider, which is the underlying
class that performs the low-level tasks of storing and retrieving profile data.
You can use the profile provider included with the .NET Framework, which stores
profile data in SQL Server, or you can create and use your own profile provider
as described in the topic implementing
a Profile Provider. You can specify an instance of the Sql Profile Provider that connects to a database of your choosing, or you
can use the default instance of the Sql Profile Provider that stores profile data on the local Web server.You configure the profile feature by defining a list
of properties whose values you want to maintain.
For an instance, you might want to store the user’s Zip
code so that your application can offer region-specific information, such as
weather reports. In the configuration file, you would define a profile property
named Zip Code. The profile section of the
configuration file might look like the following:
<Profile>
<Properties>
<add name="Zip Code"
/>
</properties>
</profile>
When your application runs, ASP.NET creates a Profile Common class, which is a dynamically
generated class that inherits the Profile
Base class. The dynamic Profile Common class includes properties created from
the profile property definitions you specify in your application configuration.
An instance of this dynamic Profile Common class
is then set as the value of the Profile property of the current Http Context and is available to pages in your
application.
In your application,
you collect the value or values you want to store and assign them to the
profile properties you have defined. For example, your application's home page
might contain a text box that prompts the user to enter a postal code. When the
user enters a postal code, you set a Profile property to store the value for the
current user, as in the following example:
profile.zipcode=txtzipcode.text
When you set a value for Profile.ZipCode, the value is automatically stored
for the current user. You do not need to write any code to determine who the
current user is or explicitly store the value in a database—the profile feature
performs these tasks for you.
When you want to use the value, you can get it in
much the same way that you set it. For example, the following code example
shows how to call an imaginary function named Get Weather Info, passing it the current user's postal code as stored
in a profile:
weather Info = GetWeatherInfo( Profile.ZipCode )
You do not need to explicitly determine
who the user is or perform any database look ups Simply getting the
property value out of a profile causes ASP.NET to perform the necessary actions
to identify the current user and look up the value in the persistent profile
store.
No comments:
Post a Comment