About the book
This is the second chapter
of the book ASP.NET MVC in Action. It has been
published with the exclusive permission of Manning.
Written by: Jeffrey Palermo, Ben Scheirman, Jimmy Bogard, Eric Hexter, and Matthew Hinze
Pages: 432
Publisher: ManningISBN-10:
9781935182795
Get 30% discount
DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code
dns30 at checkout.
ASP.NET personalization requires database objects to be created. You can create these on your database by
running a Visual Studio 2008 Command Prompt and typing:
WPF provides strong support and powerful features for data access. WPF 4, together with the Visual Studio 2010 IDE, helps you develop data-bound applications efficiently.
This will install database support for profiles, roles, membership, and personalization on the server specified. To
define the type of data you want to store for your users, you have to define it in the web.config. Listing 1 shows a
sample configuration.
Listing 1: Setting up the personalization properties
We have identified two properties that we want to track for our users. In a Web Forms application, you would
set these values to controls on your page form, directly accessing the Profile API from your code-behind. The only
difference in ASP.NET MVC is that we need to do this in our controller. When adding items to ViewData, we can
choose between explicitly adding each property into ViewData directly and passing the entire profile object. Your
preference depends on how complex your profile properties are. Listing 2 shows a controller action that passes
profile data to the view.
Listing 2: Passing the profile dictionary to the view
#A Accessing Profile from HttpContext
#B Sending Profile to the view
Listing 3: Displaying profile data on the view
#A Displaying Profile attributes
The edit form is displayed in listing 4.
Listing 4: Displaying profile data on the view
Luckily, the Profile property is of type ProfileBase and is an abstract base class. This means we can easily
test actions that utilize profile data. Setting the profile data is basically the opposite operation: you take form
control values and put them on the profile dictionary.
Summary
In this article, we discussed setting up personalization, as well as displaying and editing profile data in ASP.NET
MVC.
Get 30% discount
DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code
dns30 at checkout.
About Manning Publications
 |
Manning Publication publishes computer books for professionals--programmers, system administrators, designers, architects, managers and others. Our focus is on computing titles at professional levels. We care about the quality of our books. We work with our authors to coax out of them the best writi...
This author has published 33 articles on DotNetSlackers. View other articles or the complete profile here.
|
You might also be interested in the following related blog posts
PUBLIC SECTOR WEBCAST: Introduction to ASP.NET AJAX
read more
Module Settings and Personalization: Easily Store Data For Your DotNetNuke Module
read more
Building a better ASP.NET 2.0 user experience with Microsoft AJAX technologies
read more
This blog is now running SUBV2
read more
|
|
Please login to rate or to leave a comment.