Professional Documents
Culture Documents
NET Core
Users can create an account with the login information stored in Identity or they can use an external login
provider. Supported external login providers include Facebook, Google, Microsoft Account, and Twitter.
Identity is typically configured using a SQL Server database to store usernames, passwords, and profile
data. In this topic, you learn how to use Identity to register, log in, and log out a user.
Note:
The templates treat username and email as the same for users.
3. From the left pane of the Add New Scaffolded Item dialog, tap Identity. Then, select the
Identity and tap Add.
• Tap the + button in data context class column to create a new Data Context (Database) class
for the identity function.
• In the Add Data Context dialog -
• Use the default data context type name and tap Add:
MVC_APU_FlowerShop2023.Data.MVC_APU_FlowerShop2023Context.
NOTE:
The system will use your project name as the base name of the SQL database name.
• Use the default user class type name and tap Add: MVC_APU_FlowerShop2023User.
• Once the Add Identity dialog is done (as shown as below), tap Add button.
5. Lastly, a folder named “Areas” will be appearing in the Solution Explorer corner. The
screenshot as below:
6. In your appsettings.json, you will see the database connection is auto generated and
attached in the file (shown as below).
8. Open your "Program.cs" file and make sure no errors are found. If an error occurs, please
edit until there is no error.
9. Once your project gets screens similar to the above, it means Identity Framework Core is
now integrated with your project. You can now start designing registration pages, login
pages, and user profile pages in your application.
b. Add the registration, login, and user profile pages in your existing project.
(Estimated Total Time Used: 30 minutes)
7. Tap F5 to run the app in debug mode or Ctrl-F5 in non-debug mode. You will now see
that the register and login buttons appear on the website.
1. To create a database for storing user information, you must use the Package Manager
Console (PMC).
2. To start the PMC, click on the Tools > NuGet Package Manager > Package Manager
Console.
3. In the Visual Studio Package Manager Console, type the below commands:
Add-Migration CreateIdentitySchema
OR
If an error occurs as below, please follow the following step. Otherwise, ignore this
step!
A migration code will be generated after the add-migration command. This migration code
will create the structural schema of the tables for the new database.
After creating a migration file using the add-migration command, you must update the
database. Execute the Update-Database command to create or modify a database schema.
Update-Database
4. Now, in Visual Studio, open the SQL Server Object Explorer (SSOX).
5. To connect to the local SQL database in SSOX, follow the below step.
6. Once you connected to the local SQL database, you will see your database
“MVC_APU_FlowerShop2023” located in the SQL Server and all the default tables are
under the database.
7. Once every above step is done, let’s test the application now.
a. Register a new user.
b. Click on the “Click here to confirm your account.” to verify your account.
c. Click on the Login button now. Use the previous user credentials to login.
d. Select the new username (next to the Logout link). You might need to expand the
window or select the navigation bar icon to show the username and other links.
Summary:
• We have learnt how to create a simple authentication feature in an existing ASP .Net Core Web
Application in Visual Studio.