This is part one of the ASP.NET Content Rater Web Site series. In this tutorial we will begin setting up the web form and databases using ASP.NET 4.0 and C#.

The Goal

This tutorial is the first part of a series that will be walking you through step by step how to create a simple web site with content that your users can apply ratings to. For this example, we will use a database with some books in it and allow the user to associate a rating between 1 to 5 for each of those books respectively.

Enabling Users

First, we will need to go ahead and create a web site with users enabled and create an account that we will use to test the ratings out with. To do this, create a new ASP.NET Empty Web Site and:

  1. Click the ASP.NET Configuration icon in your solution explorer.
  2. Click the security tab.
  3. Click select authentication type.
  4. Select from the internet.
  5. Click done.
  6. Click create user.
  7. Fill out the form and click create user.
  8. Close the ASP.NET Web Site Administration Tool.

The Database

Now that we have enabled users and have created an account to test our web site with, we need to add the database that will hold all of our books and ratings. To do this:

  1. Click the refresh icon in your solution explorer.
  2. Notice the App_Data folder was added when we enabled user creation.
  3. Right click the App_Data folder.
  4. Select add new item…
  5. Select a SQL server database.
  6. Name it ‘Database.mdf’.
  7. Click add.

This database will need to hold two tables, one to hold our book data and a second to hold our user’s ratings. To add the books table:

  1. Expand your Database.mdf folder in your server/database explorer.
  2. Right click the Tables folder.
  3. Select Add New Table.
  4. Add the following columns with their respective types:
    Column Name Data Type
    BookId int
    Title nvarchar(255)
    Author nvarchar(50)
  5. Right click the BookId column.
  6. Select Set Primary Key.
  7. Change the IsIdentity property of the BookId column to ‘Yes’.
  8. Save the table as ‘Books’.

Next, we need to add some sample data into the books column so our users will have something to rate. To do this:

  1. Right click the Books table.
  2. Select Show Table Data.
  3. Add in the following books:
    BookId Title Author
    1 The Adventures of Huckleberry Finn Mark Twain
    2 The Grapes of Wrath John Steinbeck
    3 The Great Gatsby F. Scott Fitzgerald
    4 Moby Dick ;Herman Melville
    5 A Tale of Two Cities Charels Dickens
     6 To Kill a Mockingbird Harper Lee
    7 Wuthering Heights Emily Bronte

The Form
Next, we will need to add in a page to our web site that will have a login control for the user to login and also display the books for our users to rate. To do this:

  1. Right click the project in your solution explorer.
  2. Select add new item…
  3. Select a web form.
  4. Name it ‘Default.aspx’.
  5. Click add.
  6. Drag and drop a loginview control onto the web form.
  7. Add the following text to the anonymoustemplate of the loginview: ‘Login to view your ratings.’
  8. Drag and drop a login control into the anonymoustemplate.
  9. Add a few break lines after the loginview.
  10. Drag and drop a repeater after the break lines.

This form will only display a login control if the user is not logged in. Under the login control, we have added a repeater which we will use to display the books with their appropriate ratings. This concludes part one of the tutorial, we have setup a database and a form that we will use to add in the rest of our functionality so the users can apply their own ratings to the books in our database.
Download Source Files