程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类?

开发过程中遇到ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类的问题如何解决?下面主要结合日常开发的经验,给出你关于ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类的解决方法建议,希望对你解决ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类有所启发或帮助;

尝试在项目中添加第一个迁移时遇到的问题:

访问 Microsoft.Extensions.HosTing 服务时出错。在没有应用程序服务提供商的情况下继续。错误:无法构建某些服务(验证服务描述符时出错:“serviCEType: Microsoft.AspNetCore.IDentity.ISecurityStampValIDator lifetime: Scoped ImplementationType: Microsoft.AspNetCore.IDentity.SecurityStampValIDator1[API.EntitIEs.AppUser]': Unable to resolve service for type 'Microsoft.AspNetCore.Authentication.ISy@R_502_6563@Clock' while attempTing to activate 'Microsoft.AspNetCore.IDentity.SecurityStampValIDator1[API.EntitIEs. AppUser]'。)(验证服务描述符“serviCEType:Microsoft.AspNetCore.IDentity.ITwoFactorSecurityStampValIDator lifetime:Scoped ImplementationType:Microsoft.AspNetCore.IDentity.TwoFactorSecurityStampValIDator1[API.EntitIEs.AppUser]': Unable to resolve service for type 'Microsoft.AspNetCore.Authentication.ISy@R_502_6563@Clock' while attempTing to activate 'Microsoft.AspNetCore.IDentity.TwoFactorSecurityStampValIDator1[API.EntitIEs.AppUser]”时出错。) 无法创建类型为“DataContext”的对象。有关设计时支持的不同模式,请参阅 https://go.microsoft.com/fwlink/?linkid=851728

继承IDentityDbContext的类:

public class DataContext : IDentityDbContext<AppUser,AppRole,int,IDentityUserClaim<int>,AppUserRole,IDentityUserLogin<int>,IDentityRoleClaim<int>,IDentityUserToken<int>>
    {

        public DataContext(DbContextoptions<DataContext> options) : base(options)
        {
            
        }
         DbSet<CVUser> UserWithCV { get; set; }

        //Fluent API - used to overwrite the EF Core conventions
        protected overrIDe voID OnModelCreaTing(ModelBuilder modelBuilder)
        {
            base.onModelCreaTing(modelBuilder);
        }

然后我有 AppUser,它继承了 IDentityUser

创业班:

public voID Configureservices(IserviceCollection services)
        {
            services.AddDbContext<DataContext>(options =>
            {
                optionS.Usesqlite(_config.GetConnectionString("DefaultConnection"));
            });
            services.AddControllers();
            //SetTing up the IDentity API
            services.AddIDentityCore<AppUser>
            (options =>
                options.password.requireNonAlphanumeric = false
            )
            
            .AddRoles<AppRole>()
            .AddRoleManager<RoleManager<AppRole>>()
            .AddRoleValIDator<RoleValIDator<AppRole>>()
            .AddEntityFrameworkStores<DataContext>()
            .AddSignInManager<SignInManager<AppUser>>(); //  - here is the problem
                                                         
        }
.AddSignInManager<SignInManager<AppUser>>();

在尝试向项目添加新迁移时,这一行导致了我的问题。知道为什么吗?

我唯一的解决方案是删除以下所有内容:(我猜 IDentity 会默认正确创建它们) (如果我删除 AddSignInManager 我可以创建迁移)

.AddRoles<AppRole>()
.AddRoleManager<RoleManager<AppRole>>()
.AddRoleValIDator<RoleValIDator<AppRole>>()
.AddSignInManager<SignInManager<AppUser>>();

你怎么看?谢谢。

解决方法

似乎我缺少 services.AddAuthentication()。 感谢@marTinCostello 的帮助

大佬总结

以上是大佬教程为你收集整理的ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类全部内容,希望文章能够帮你解决ASP.NET CORE / 添加 .AddSignInManager<SignInManager<AppUser>>() 时遇到的问题;在启动类所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:/添加