Published: 14 Jun 2010
By: Manning Publications

This article is taken from the book ASP.NET MVC 2 in Action. The authors discuss setting up and editing a profile.



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: Manning
ISBN-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.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

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.

Other articles in this category


ASP.NET MVC Dynamic Model Binding
Dynamic model binding enables a single action to handle multiple forms.
Using HTML5 Web Storage in ASP.NET
HTML5 Web Storage provides a streamlined data storage mechanism that allows developers to store data...
Implementing Website Pinning in ASP.NET
Learn to enable website pinning features of IE9 on Windows 7 for your ASP.NET websites.
Building a YouTube-like Video Playing Site Using ASP.NET Techniques - Part 3
In this final part of this series, we are going to discuss how to make the users play their selected...
Running multiple websites in a single hosting space
Develop a solution that supports multiple websites in a single hosting space and database.

You might also be interested in the following related blog posts


Module Settings and Personalization: Easily Store Data For Your DotNetNuke Module read more
This blog is now running SUBV2 read more
Building a better ASP.NET 2.0 user experience with Microsoft AJAX technologies read more
PUBLIC SECTOR WEBCAST: Introduction to ASP.NET AJAX read more
Top
 
 
 

Please login to rate or to leave a comment.