【问题标题】:IserviceCollection does not contain defination of "AddDefaultIdentity"IserviceCollection 不包含“AddDefaultIdentity”的定义
【发布时间】:2020-04-27 14:02:54
【问题描述】:

AddDefaultIdentity 抛出错误

'IServiceCollection' does not contain a definition for 'AddDefaultIdentity' and 

no accessible extension method 'AddDefaultIdentity' accepting a first argument 

of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

WebApiDotNet.AddDefaultIdentityIServiceCollection 中不存在

【问题讨论】:

  • Startup.cs 中的 Identity 配置代码是什么?

标签: c# asp.net-core


【解决方案1】:

“IServiceCollection”不包含“AddDefaultIdentity”的定义,并且找不到接受“IServiceCollection”类型的第一个参数的可访问扩展方法“AddDefaultIdentity”(您是否缺少 using 指令或程序集引用?)

当我在 3.0 项目中安装高于 3.0 版本的 Microsoft.AspNetCore.Identity.UI 包时,我重现了该问题。 注意: AddDefaultIdentity 扩展方法用于为 Razor Pages 和 MVC 添加默认 UI 服务。

您可以使用AddIdentity 代替AddDefaultIdentity,如下所示:

services.AddIdentity<ApplicationUser,IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

如果你想使用AddDefaultIdentity,你应该将Microsoft.AspNetCore.Identity.UI的版本更新到3.0。

AddDefaultIdentity 和 AddIdentity 的区别可以参考https://medium.com/@xsoheilalizadeh/asp-net-core-identity-deep-dive-stores-e0e54291b51d

【讨论】:

    猜你喜欢
    • 2020-08-20
    • 2019-10-19
    • 1970-01-01
    • 2019-06-09
    • 2022-01-03
    • 1970-01-01
    • 2020-04-02
    • 1970-01-01
    • 2019-04-14
    相关资源
    最近更新 更多