Is there an existing issue for this?
Describe the bug
Blazor Identity scaffolds Identity into the wrong folder when db context already exists
Scaffolding Blazor Identity into a project with an existing context adds an {APP NAMESPACE} > Components folder using the app's name. The folder contains its own Components folder, which contains the Account folder, which contains the Identity assets ...

This is incorrect. The Account folder should be placed in the app's existing Components folder. Because the Identity components are placed the way they are, there are 174 type and namespace violations. This is because the namespaces don't have a double app name in them. The scaffolder correctly makes the namespaces to Account assets with a single BlazorWebAppMovies namespace segment. For example, the Razor components (Pages assets) for Identity are correctly referenced as ...
using BlazorWebAppMovies.Components.Account.Pages;
Also, scaffolding creates an Account > Shared folder in the app's existing Components folder, which is correct, and places just one file in it ... PasskeySubmit.razor.js, but the Razor component that would go with the file (PasskeySubmit.razor) is in the incorrectly-added BlazorWebAppMovies > BlazorWebAppMovies > Components > Account > Shared folder.
The same thing happens if you try to scaffold Identity using a new db context into this sample app.
Expected Behavior
The Account folder should be placed in the app's existing Components folder.
Steps To Reproduce
I'm beginning this process with the Blazor movie dB sample app, which has an existing context ...
The purpose of this is to use the movie dB sample app as the starter app for a different tutorial on using authz in ASP.NET Core at https://learn.microsoft.com/aspnet/core/security/authorization/secure-data. The current article is based on Razor Pages, and we want the article to be based on Blazor.
I used the following steps. The first three steps are to get the existing db context set up to inherit from IdentityDbContext, which is required for scaffolding using an existing context. However, the same outcome occurs if I create a new database context just for Identity.
-
Install NuGet package: Microsoft.AspNetCore.Identity.EntityFrameworkCore
-
Add an application user.
Data/ApplicationUser.cs:
using Microsoft.AspNetCore.Identity;
namespace BlazorWebAppMovies.Data;
public class ApplicationUser : IdentityUser
{
// Add custom user properties here
}
-
Change BlazorWebAppMoviesContext to inherit from IdentityDbContext<ApplicationUser>:
- public class BlazorWebAppMoviesContext : DbContext
+ public class BlazorWebAppMoviesContext : IdentityDbContext<ApplicationUser>
-
In Solution Explorer, right-click the project and select Add > New Scaffolded Item.
-
In the Add New Scaffolded Item dialog, select Identity > Blazor Identity. Select the Add button.
-
In the Add Blazor Identity dialog, select BlazorWebAppMoviesContext for the DbContext class. Select the Add button to scaffold Identity into the app. Wait until the scaffolding process is complete.
Exceptions (if any)
None
.NET Version
10.0.201
Anything else?
No response
Is there an existing issue for this?
Describe the bug
Blazor Identity scaffolds Identity into the wrong folder when db context already exists
Scaffolding Blazor Identity into a project with an existing context adds an
{APP NAMESPACE}>Componentsfolder using the app's name. The folder contains its ownComponentsfolder, which contains theAccountfolder, which contains the Identity assets ...This is incorrect. The
Accountfolder should be placed in the app's existingComponentsfolder. Because the Identity components are placed the way they are, there are 174 type and namespace violations. This is because the namespaces don't have a double app name in them. The scaffolder correctly makes the namespaces toAccountassets with a singleBlazorWebAppMoviesnamespace segment. For example, the Razor components (Pagesassets) for Identity are correctly referenced as ...Also, scaffolding creates an
Account>Sharedfolder in the app's existingComponentsfolder, which is correct, and places just one file in it ...PasskeySubmit.razor.js, but the Razor component that would go with the file (PasskeySubmit.razor) is in the incorrectly-addedBlazorWebAppMovies>BlazorWebAppMovies>Components>Account>Sharedfolder.The same thing happens if you try to scaffold Identity using a new db context into this sample app.
Expected Behavior
The
Accountfolder should be placed in the app's existingComponentsfolder.Steps To Reproduce
I'm beginning this process with the Blazor movie dB sample app, which has an existing context ...
The purpose of this is to use the movie dB sample app as the starter app for a different tutorial on using authz in ASP.NET Core at https://learn.microsoft.com/aspnet/core/security/authorization/secure-data. The current article is based on Razor Pages, and we want the article to be based on Blazor.
I used the following steps. The first three steps are to get the existing db context set up to inherit from
IdentityDbContext, which is required for scaffolding using an existing context. However, the same outcome occurs if I create a new database context just for Identity.Install NuGet package:
Microsoft.AspNetCore.Identity.EntityFrameworkCoreAdd an application user.
Data/ApplicationUser.cs:Change
BlazorWebAppMoviesContextto inherit fromIdentityDbContext<ApplicationUser>:In Solution Explorer, right-click the project and select Add > New Scaffolded Item.
In the Add New Scaffolded Item dialog, select Identity > Blazor Identity. Select the Add button.
In the Add Blazor Identity dialog, select
BlazorWebAppMoviesContextfor the DbContext class. Select the Add button to scaffold Identity into the app. Wait until the scaffolding process is complete.Exceptions (if any)
None
.NET Version
10.0.201
Anything else?
No response