我正在尝试在aspnet样板中使用Identity实现忘记密码。
IdentityProject
)。App_Start/AppIdentityConfig.cs
和IdentityModels
文件从IdentityProject
复制到ABPProject
。Startup.cs
方法的Configuration
课程中将此行写下来:app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
以下是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但未处理 用户代码
以下是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)
{
}
}
这个例外可能是什么原因以及如何解决这个问题?