Fun Pet Trick 9: Profile Object


Fun Pet Trick #9: Profile Object

By Scott Guthrie

The Profile Management feature within ASP.NET 2.0 is pretty cool. Basically it enables you to save and retrieve properties about incoming users to your application.

Unlike session state, this profile information is saved within a personalization store database and not deleted unless the administrator explicitly gets rid of it. As such, you can use it to store information about users for days, weeks, or years at a time. You can also do back-end data mining on the information to help optimize your application's experience even further.

To enable this feature, create a web.config file within your web application virtual root that looks like this:

 <configuration>     <system.web>           <personalization>                  <profile>                         <property name="NickName" type="string"/>                  </profile>           </personalization>           <authentication mode="Windows"/>           <authorization>                 <deny users="?"/>           </authorization>     </system.web> </configuration> 

This will define a personalization store with a single property called NickName that can be accessed or stored for any user hitting the system.

To update the NickName property for a calling user, just write code within your page as follows (note that VS .NET provides full IntelliSense support on the Profile object):

 Profile.NickName = TextBox1.Text 

You can then print the nickname like so:

 Label1.Text = "Hello " & Profile.NickName 

Under the covers, ASP.NET then handles saving and restoring the profile settings to and from a database. This makes it incredibly easy to add or update personalization settings for users and provide a much richer browsing experience within applications as a result.




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net