Skip to content

Blazor Identity scaffolds Identity into the wrong folder when a db context already exists #3716

Closed

Description

@guardrex

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 ...

Image

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.

  1. Install NuGet package: Microsoft.AspNetCore.Identity.EntityFrameworkCore

  2. Add an application user.

    Data/ApplicationUser.cs:

    using Microsoft.AspNetCore.Identity;
    
    namespace BlazorWebAppMovies.Data;
    
    public class ApplicationUser : IdentityUser
    {
        // Add custom user properties here
    }
  3. Change BlazorWebAppMoviesContext to inherit from IdentityDbContext<ApplicationUser>:

    - public class BlazorWebAppMoviesContext : DbContext
    + public class BlazorWebAppMoviesContext : IdentityDbContext<ApplicationUser>
  4. In Solution Explorer, right-click the project and select Add > New Scaffolded Item.

  5. In the Add New Scaffolded Item dialog, select Identity > Blazor Identity. Select the Add button.

  6. 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

Activity

  1. guardrex commented on Apr 9, 2026

    @guardrex
    Author

    @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!

  2. guardrex commented on Apr 9, 2026

    @guardrex
    Author

    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.

  3. haileymck commented on Apr 17, 2026

    @haileymck
    Member

    @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!

  4. guardrex commented on Apr 20, 2026

    @guardrex
    Author

    Visual Studio 2026 Community Edition (Version: Insiders 11626.173)

  5. haileymck commented on Apr 23, 2026

    @haileymck
    Member

    ok thanks! Will work on addressing you issue!

  6. guardrex commented on Jul 22, 2026

    @guardrex
    Author

    @haileymck ... Was this one fixed (if so, for the public .NET 10 package)? I can check again if you're not sure.

  7. added
    area-dotnet-scaffolding
    on Aug 7, 2026
  8. added theissue type on Aug 7, 2026
  9. guardrex commented on Aug 17, 2026

    @guardrex
    Author

    @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 ...

    1. Create a folder for the app: BlazorWebAppMoviesAuthorization.
    2. Copy the BlazorWebAppMovies sample files into the folder (sans folders: bin, obj, .config ... btw ... I'm removing the .config folder from that sample now).
    3. Confirm that the latest Microsoft.dotnet-scaffold tool is installed, which is 20.0.0.
    4. Open a command shell to the app. Execute dotnet scaffold with the following:
      • Pick a scaffolding category: (Show All)
      • Pick a scaffolding command: Blazor Identity (dotnet-scaffold)
      • .NET project file: BlazorWebAppMovies (BlazorWebAppMovies.csproj)
      • Enter a new value for 'Data Context Class' (< to go back): Typed in BlazorWebAppMoviesContext (the existing db context)
      • Database Provider: sqlserver-efcore
      • Overwrite existing files?: Yes

    Result: The Identity components are placed in a folder named after the app (BlazorWebAppMovies) at the root of the app instead of the app's own Components/Account folder. The app's existing Components/Account folder 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.

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorarea-dotnet-scaffolding

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions