ASP.NET Core: Authentication

Menu
Menu

Authentication Registration Page

Our authentication set up needs three pages, a register page, a signin page and a signout page.

Set Up the Model

Registration will be build around the following model. Add the model to your Models folder.

Models/Register.cs

No need to run a migration as the table for this data was created in the last step.

Set up the Security Controller

To keep the logic maintainable we'll create a new Controller for the security features of the applications.

Create a new Controller as Controllers/SecurityController.cs:

CONTROLLER: Controllers/SecurityController.cs

Notice that a role of manager is hard coded into this example.

Next add a View Pages/Secure/Register.cshtml

VIEW: Views/Security/Register.cshtml

Run the application and browse to https://localhost:44354/Security/Register. Fill out the form to create a new user.

By default, Identity requires that passwords contain an uppercase character, lowercase character, a digit, and a non-alphanumeric character. Passwords must be at least six characters long.

Option can be configured see the Microsoft Documentation.

Currently the View/Security/SignIn that the registration will redirect to does not exist. We'll do that shortly.