Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 100 additions & 14 deletions aspnetcore/security/authentication/identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ uid: security/authentication/identity

:::moniker range=">= aspnetcore-8.0"

By [Rick Anderson](https://twitter.com/RickAndMSFT)

ASP.NET Core Identity:

* Is an API that supports user interface (UI) login functionality.
Expand All @@ -28,6 +26,8 @@ Identity is typically configured using a SQL Server database to store user names

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. For more detailed instructions about creating apps that use Identity, see [Next Steps](#next).

For more information on Identity in Blazor apps, see <xref:blazor/security/index> and the articles that follow it in the Blazor documentation.

ASP.NET Core Identity isn't related to the [Microsoft identity platform](/azure/active-directory/develop/). Microsoft identity platform is:

* An evolution of the Azure Active Directory (Azure AD) developer platform.
Expand All @@ -39,34 +39,119 @@ ASP.NET Core Identity isn't related to the [Microsoft identity platform](/azure/

<a name="adi"></a>

## Create a Web app with authentication
## Create a Blazor Web App with authentication

Create an ASP.NET Core Blazor Web App project with Individual Accounts.

Create an ASP.NET Core Web Application project with Individual Accounts.
> [!NOTE]
> For a Razor Pages experience, see the [Create a Razor Pages app with authentication](#create-a-razor-pages-app-with-authentication) section.
>
> For an MVC experience, see the [Create an MVC app with authentication](#create-an-mvc-app-with-authentication) section.

# [Visual Studio](#tab/visual-studio)

* Select the **ASP.NET Core Web App** template. Name the project **WebApp1** to have the same namespace as the project download. Click **OK**.
* In the **Authentication type** input, select **Individual Accounts**.
* Select the **Blazor Web App** template. Select **Next**.
* Make the following selections:
* **Authentication type**: **Individual Accounts**
* **Interactive render mode**: **Server**
* **Interactivity Location**: **Global**
* Select **Create**.

# [.NET CLI](#tab/net-cli)

```dotnetcli
dotnet new webapp --auth Individual -o WebApp1
dotnet new blazor -au Individual -o BlazorApp1
```

The preceding command creates a Razor web app using SQLite. To create the web app with LocalDB, run the following command:
The `-o|--output` option creates a folder for the app and sets the app name/namespace.

The preceding command creates a Blazor Web App using SQLite. To create the app with LocalDB, run the following command:

```dotnetcli
dotnet new webapp --auth Individual -uld -o WebApp1
dotnet new blazor -au Individual -uld -o BlazorApp1
```

---

The generated project provides [ASP.NET Core Identity](xref:security/authentication/identity) as a [Razor class library](xref:razor-pages/ui-class). The Identity Razor class library exposes endpoints with the `Identity` area. For example:
The generated project includes Identity Razor components. The components are found in the `Components/Account` folder. For example:

* `/Components/Account/Pages/Register`
* `/Components/Account/Pages/Login`
* `/Components/Account/Pages/Manage/ChangePassword`

Identity Razor components are described individually in the documentation for specific use cases and are subject to change each release. When you generate a Blazor Web App with Individual Accounts, Identity Razor components are included in the generated project. The Identity Razor components can also be inspected in the [Blazor project template in the ASP.NET Core reference source (`dotnet/aspnetcore` GitHub repository)](https://github.com/dotnet/aspnetcore/tree/main/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account).

[!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)]

For more information, see <xref:blazor/security/index> and the articles that follow it in the Blazor documentation. Most of the articles in the *Security and Identity* area of the main ASP.NET Core documentation set apply to Blazor apps. However, the Blazor documentation set contains articles and guidance that supersedes or adds information. We recommend studying the general ASP.NET Core documentation set first, followed by accessing the articles in the Blazor *Security and Identity* documentation.

## Create a Razor Pages app with authentication

Create an ASP.NET Core Web Application (Razor Pages) project with Individual Accounts.

# [Visual Studio](#tab/visual-studio)

* Select the **ASP.NET Core Web App (Razor Pages)** template. Select **Next**.
* For **Authentication type**, select **Individual Accounts**.
* Select **Create**.

# [.NET CLI](#tab/net-cli)

```dotnetcli
dotnet new webapp -au Individual -o WebApp1
```

The `-o|--output` option creates a folder for the app and sets the app name/namespace.

The preceding command creates a Razor Pages app using SQLite. To create the app with LocalDB, run the following command:

```dotnetcli
dotnet new webapp -au Individual -uld -o WebApp1
```

---

The generated project provides [ASP.NET Core Identity](xref:security/authentication/identity) as a [Razor class library (RCL)](xref:razor-pages/ui-class). The Identity Razor class library exposes endpoints with the `Identity` area. For example:

* `Areas/Identity/Pages/Account/Register`
* `Areas/Identity/Pages/Account/Login`
* `Areas/Identity/Pages/Account/Manage/ChangePassword`

Pages are described individually in the documentation for specific use cases and are subject to change each release. To view all of the pages in the RCL, see the [ASP.NET Core reference source (`dotnet/aspnetcore` GitHub repository, `Identity/UI/src/Areas/Identity/Pages` folder)](https://github.com/dotnet/aspnetcore/tree/main/src/Identity/UI/src/Areas/Identity/Pages). You can *scaffold* individual pages or all of the pages into the app. For more information, see <xref:security/authentication/scaffold-identity>.

## Create an MVC app with authentication

Create an ASP.NET Core MVC project with Individual Accounts.

# [Visual Studio](#tab/visual-studio)

* Select the **ASP.NET Core Web App (Model-View-Controller)** template. Select **Next**.
* For **Authentication type**, select **Individual Accounts**.
* Select **Create**.

# [.NET CLI](#tab/net-cli)

```dotnetcli
dotnet new mvc -au Individual -o WebApplication1
```

The `-o|--output` option creates a folder for the app and sets the app name/namespace.

The preceding command creates an MVC app using SQLite. To create the web app with LocalDB, run the following command:

```dotnetcli
dotnet new mvc -au Individual -uld -o WebApplication1
```

---

The generated project provides [ASP.NET Core Identity](xref:security/authentication/identity) as a [Razor class library (RCL)](xref:razor-pages/ui-class). The Identity Razor class library is based on Razor Pages and exposes endpoints with the `Identity` area. For example:

* `Areas/Identity/Pages/Account/Register`
* `Areas/Identity/Pages/Account/Login`
* `Areas/Identity/Pages/Account/Manage/ChangePassword`

* /Identity/Account/Login
* /Identity/Account/Logout
* /Identity/Account/Manage
Pages are described individually in the documentation for specific use cases and are subject to change each release. To view all of the pages in the RCL, see the [ASP.NET Core reference source (`dotnet/aspnetcore` GitHub repository, `Identity/UI/src/Areas/Identity/Pages` folder)](https://github.com/dotnet/aspnetcore/tree/main/src/Identity/UI/src/Areas/Identity/Pages). You can *scaffold* individual pages or all of the pages into the app. For more information, see <xref:security/authentication/scaffold-identity>.

### Apply migrations

Expand Down Expand Up @@ -243,10 +328,11 @@ To prevent publishing static Identity assets (stylesheets and JavaScript files f

## Next Steps

* <xref:blazor/security/index>
* [ASP.NET Core Identity source code](https://github.com/dotnet/aspnetcore/tree/main/src/Identity)
* [How to work with Roles in ASP.NET Core Identity](https://www.yogihosting.com/aspnet-core-identity-roles/)
<!-- https://github.com/dotnet/AspNetCore.Docs/issues/7114 -->
* See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/5131) for information on configuring Identity using SQLite.
* For information on configuring Identity using SQLite, see [How to config Identity for SQLite (`dotnet/AspNetCore.Docs` #5131)](https://github.com/dotnet/AspNetCore.Docs/issues/5131).
* [Configure Identity](xref:security/authentication/identity-configuration)
* <xref:security/authorization/secure-data>
* <xref:security/authentication/add-user-data>
Expand Down