在aspnet样板中实现忘记密码

时间:2017-08-10 05:49:22

标签: c# entity-framework asp.net-identity aspnetboilerplate

我正在尝试在aspnet样板中使用Identity实现忘记密码。

  1. 我在visual studio中创建了一个新项目,该项目具有单独的用户身份验证,并实现并测试了忘记密码功能(项目名称:IdentityProject)。
  2. 然后我下载了abp项目并将App_Start/AppIdentityConfig.csIdentityModels文件从IdentityProject复制到ABPProject
  3. Startup.cs方法的Configuration课程中将此行写下来:app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
  4. 以下是ApplicationUserManager中的IdentityConfig.cs课程:

    public class ApplicationUserManager : UserManager<ApplicationUser>
    {
        public ApplicationUserManager(IUserStore<ApplicationUser> store)
            : base(store)
        {
        }
    
        public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) 
        {
            var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator<ApplicationUser>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail = true
            };
    
            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6,
            };
    
            //removed some of the  configuration code..
    
            var dataProtectionProvider = options.DataProtectionProvider;
            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider = 
                    new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return manager;
        }
    }
    

    在运行应用程序时,我在Create方法的第一行获得了异常:

      

    值不能为空。参数名称:context

         

    发生了'System.ArgumentNullException'类型的异常   Microsoft.AspNet.Identity.EntityFramework.dll但未处理   用户代码

    虽然context参数包含以下数据:

    以下是ApplicationDbContext标识类:

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection", throwIfV1Schema: false)
        {
        }
    
        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }
    

    以下是ABPProjectDBContext的类:

    public class HRISDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
    
        public HRISDbContext()
            : base("Default")
        {
    
        }
        public HRISDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
    
        }
    
        //This constructor is used in tests
        public HRISDbContext(DbConnection existingConnection)
         : base(existingConnection, false)
        {
    
        }
    
        public HRISDbContext(DbConnection existingConnection, bool contextOwnsConnection)
         : base(existingConnection, contextOwnsConnection)
        {
    
        }
    }
    

    这个例外可能是什么原因以及如何解决这个问题?

0 个答案:

没有答案