【问题标题】:User class entry is disabled in Add Identity dialog box在添加身份对话框中禁用用户类条目
【发布时间】:2021-10-27 00:30:03
【问题描述】:

我正在尝试搭建一些身份页面。但是,虽然我可以选择要覆盖的文件并选择我的数据库上下文类,但选择我的用户类的框被禁用了。

并且尝试在不设置用户类的情况下添加脚手架会产生错误。

运行所选代码生成器时出错:

'包恢复失败。回滚“Railtrax”的包更改。

这个脚手架功能对我来说大约 90% 的时间都失败了。我不知道为什么不能让它更可靠。

请注意,我确实定义了我的用户类。

public class ApplicationUser : IdentityUser
{
    // ...
}

我在我的数据库上下文类中引用它。

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    // ...
}

所以我不明白为什么它不起作用。谁能看到我可能遗漏了什么?

【问题讨论】:

    标签: c# asp.net asp.net-identity razor-pages asp.net5


    【解决方案1】:

    我遇到了这个错误,不得不将身份 Microsoft.AspNetCore.Identity.UI 恢复到旧版本

    所以它在 csproj 中看起来像这样

              <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.2" />
                <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
                <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
        
         
            <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
            <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.6" />
           
            <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
      </PackageReference>
            <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
            <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6">
              <PrivateAssets>all</PrivateAssets>
              <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            </PackageReference>
            <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
    

    【讨论】:

    • 您使用的是什么版本的 ASP.NET?这看起来不像 Razor Pages。
    • 我在 .NET 5 中使用 Asp.Net core mvc。身份库和 ef 核心版本有时会出现这些错误
    【解决方案2】:

    我也遇到了同样的错误。这不是由于您的 User 类。实际上,如果您在该窗口中手动按“+”输入您的 Db 上下文,它将允许您找到 User 类,但您仍然会遇到相同的错误。问题在于您的 CodeGenerator。我尝试安装不同版本的 CodeGenerator,但没有帮助。 然而,我确实找到了一种有效的脚手架身份的方法。 在项目文件夹中运行命令行。

    dotnet tool install -g dotnet-aspnet-codegenerator
    

    如果你已经安装了然后运行

     dotnet aspnet-codegenerator identity --help 
    

    查看所有参数。 或者只是运行

    dotnet aspnet-codegenerator identity -dc MyApplication.Data.ApplicationDbContext --files "Account.Register;Account.Login"
    

    -dc 显示应用程序上下文的路径,如果您只想要特定页面,则显示 --files,但我只是在没有它的情况下运行,然后删除了我不想要的页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-07
      • 2015-10-04
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      相关资源
      最近更新 更多