views:

722

answers:

3

i am new to asp.net mvc so please be explicit as possible.

Here is my goal:

i want to create a simple website where users can:

  1. Register and log in
  2. Enter there contact details(phone, address, etc)
  3. View there contact details
  4. Edit details of #3.

Later in the website, i will create other pages that use this data but for now the only items above are needed.

my questions is that i have been reviewing the default asp.net mvc sample that comes when you create a new asp.net mvc app.

I am trying to figure out if i should store all the contact details in the aspnetdb.mdf database in an existing table or i should be creating new tables.

it seems like i could extend aspnet_Users or aspnet_membership.

please let me know if these tables can be extended to store additional fields or if its safer to just create a new table in this database.

+3  A: 

You could use an Asp.net profile provider to store the information. Follow the link for instructions on using the built-in SqlProfileProvider. By default, the SqlProfileProvider will create tables in the aspnetdb.mdf file, so you can keep everything in one place. You can access the profile provider as a property on the HttpContext.

Edit: Better link for ASP.Net profile information

Using the Profile provider, you don't have to worry about making database calls or identifying the current user. It's all done on your behalf. Double-check the documentation, because the following might be a little off.

You add the fields that you want in your web.config inside <system.web>. In your case, it would be the necessary contact information.

<profile>
  <properties>
    <add name="Address" />
    <add name="City" />
    <add name="State" />
    <plus other fields ... />
  </properties>
</profile>

Then, you can access HttpContext.Profile.Address and so forth and the provider will take care of tying everything to the current user.

Adding and editing the information means displaying a form. Viewing the details is just displaying all the fields you saved from the previous form post.

The NerdDinner source and tutorial are well worth checking out if you're completely new to MVC.

Ben Robbins
i am not sure you answered my question. if i extended the generated tables. how would i access these additional fields
ooo
I added some more information. I'd check out the NerdDinner tutorial, It's great stuff.
Ben Robbins
A: 

You may also want to take a look at the SQL Server Publishing Wizard found here.

It essentially allows you to copy the database structure and/or data to a .sql file that you can then import into your primary SQL database.

I don't particularly like the aspnetdb approach but that's my personal opinion.

griegs
A: 

This question has been the cause of a little bit of an internal debate for me. I can see the logic in extending the existing membership provider to hold the neccessary aditional information, however I would only use the aspnetdb database to store this information if that was the path taken, as the purpose of that database, in my mind, is to store information mamaged by ASP.NET via the Membership API

If you did decide not to extend asp.net's existing membership provider then I would suggest creating another database, or at the very least some new table(s) to keep data you are managing seperate from any other data managed by ASP.NET

Crippledsmurf