Featured resource
pluralsight tech forecast
2025 Tech Forecast

Which technologies will dominate in 2025? And what skills do you need to keep up?

Check it out
Hamburger Icon
  • Labs icon Lab
  • Core Tech
Labs

Add Authentication to an Existing ASP.NET Core Wishlist Application

In this code lab, you'll start with an ASP.NET Core Wishlist application that only supports one user with one Wishlist and has no security. You will add the ability to support multiple users with their own Wishlists secured with basic authentication.

Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 3h 22m
Published
Clock icon Apr 14, 2023

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Update ApplicationDbContext's Inheritance

    Configure the project so that authentication will be available throughout the application. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module1-solution WishList/Data/ApplicationDbContext.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module1-solution WishList/Data/ApplicationDbContext.cs

  2. Challenge

    Create AccountController

    Create a controller named AccountController that will handle actions related to authentication. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module2-solution WishList/Controllers/AccountController.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module2-solution WishList/Controllers/AccountController.cs

  3. Challenge

    Create RegisterViewModel Class

    Create Views, View Models, and add action methods to the AccountController to add the ability to register an account. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module3-solution WishList/Models/AccountViewModels/RegisterViewModel.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module3-solution WishList/Models/AccountViewModels/RegisterViewModel.cs

  4. Challenge

    Create LoginViewModel

    Fully implement the ability to login and logout of an already registered user account. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module3-solution WishList/Models/AccountViewModels/LoginViewModel.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module3-solution WishList/Models/AccountViewModels/LoginViewModel.cs

  5. Challenge

    Add Using Directives to Index View

    Update views to provide links to Login, Logout, and Register actions depending on if the user is logged in or not. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module5-solution WishList/Views/Home/Index.cshtml

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module5-solution WishList/Views/Home/Index.cshtml

  6. Challenge

    Add a Virtual ApplicationUser Property to Item

    Create a relationship between the Item and ApplicationUser models so operations on data happen for a single user's data. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module6-solution WishList/Models/Item.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module6-solution WishList/Models/Item.cs

  7. Challenge

    Add Authorize Attribute to the ItemController Class

    Update the ItemController and it's actions to use the logged in user information to allow individual users to have their own wishlists. ### Solution To view the solution, run git diff module1-solution <filepath>/<filename> in the Terminal, and press Enter to see the next lines of the difference. e.g. git diff module7-solution WishList/Controllers/ItemController.cs

    You may also update your local file browse the files of the solution by change diff to checkout e.g. git checkout module7-solution WishList/Controllers/ItemController.cs

Eric is a software developer who is passionate about always learning and improving. When he's not writing code, you'll find him playing computer games, guitar, disc golf, or learning something new.

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.