Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
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 ...
- Article: https://learn.microsoft.com/aspnet/core/blazor/tutorials/movie-database-app/
- Sample app: https://github.com/dotnet/blazor-samples/tree/main/10.0/BlazorWebAppMovies
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
BlazorWebAppMoviesContextto inherit fromIdentityDbContext<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
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

Activity
guardrex commentedon Apr 9, 2026
@haileymck ... If this turns out to be a bonafide bug, could you let me know when it would be fixed and when it would go public in what I assume would be a patch? I ask because we were going to use the movie dB tutorial as a starter app for a tutorial rewrite. I can delay having to write up the whole tutorial with a from-scratch starter app based on the project template, but I can't delay too long. If there's a bug fix that would take several weeks to roll out in a public patch, then I won't wait. Thanks!
guardrex commentedon Apr 9, 2026
Also, moving the assets to the correct locations seems to yield a different problem. The scaffolder isn't adding Identity (the tables) to the database. I suppose that I could add a migration myself that would do it, but that seems like something the scaffolder should do.
haileymck commentedon Apr 17, 2026
@guardrex Hi thanks for filing this issue, can you confirm which version of VS you are on so that I can best address your issue? Thanks!
guardrex commentedon Apr 20, 2026
Visual Studio 2026 Community Edition (Version: Insiders 11626.173)
haileymck commentedon Apr 23, 2026
ok thanks! Will work on addressing you issue!
guardrex commentedon Jul 22, 2026
@haileymck ... Was this one fixed (if so, for the public .NET 10 package)? I can check again if you're not sure.
guardrex commentedon Aug 17, 2026
@haileymck @danroth27 ... Not fixed yet. Repros with 20.0.0.
Was just getting started again with the final authz node article ✨ Blazorfication™ ✨ effort, which is for the authz tutorial at ...
https://learn.microsoft.com/aspnet/core/security/authorization/secure-data
Steps ...
BlazorWebAppMoviesAuthorization.BlazorWebAppMoviessample files into the folder (sans folders:bin,obj,.config... btw ... I'm removing the.configfolder from that sample now).Microsoft.dotnet-scaffoldtool is installed, which is 20.0.0.dotnet scaffoldwith the following:(Show All)Blazor Identity (dotnet-scaffold)BlazorWebAppMovies (BlazorWebAppMovies.csproj)BlazorWebAppMoviesContext(the existing db context)sqlserver-efcoreYesResult: The Identity components are placed in a folder named after the app (
BlazorWebAppMovies) at the root of the app instead of the app's ownComponents/Accountfolder. The app's existingComponents/Accountfolder only receives one file:PasskeySubmit.razor.js.Note that I didn't use VS for this, only the command-line scaffolder. I only opened the solution in VS to show the result.