- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech

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.

Lab Info
Table of Contents
-
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 pressEnter
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
tocheckout
e.g.git checkout module1-solution WishList/Data/ApplicationDbContext.cs
-
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 pressEnter
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
tocheckout
e.g.git checkout module2-solution WishList/Controllers/AccountController.cs
-
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 pressEnter
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
tocheckout
e.g.git checkout module3-solution WishList/Models/AccountViewModels/RegisterViewModel.cs
-
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 pressEnter
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
tocheckout
e.g.git checkout module3-solution WishList/Models/AccountViewModels/LoginViewModel.cs
-
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 pressEnter
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
tocheckout
e.g.git checkout module5-solution WishList/Views/Home/Index.cshtml
-
Challenge
Add a Virtual ApplicationUser Property to Item
Create a relationship between the
Item
andApplicationUser
models so operations on data happen for a single user's data. ### Solution To view the solution, rungit diff module1-solution <filepath>/<filename>
in the Terminal, and pressEnter
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
tocheckout
e.g.git checkout module6-solution WishList/Models/Item.cs
-
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 pressEnter
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
tocheckout
e.g.git checkout module7-solution WishList/Controllers/ItemController.cs
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.