我正在尝试在 aspnet 样板中使用身份实现忘记密码。
- 我在 Visual Studio 中创建了一个具有个人用户身份验证的新项目,并实现并测试了忘记密码功能(项目名称:)
IdentityProject
。 - 然后我下载了 abp 项目并将
App_Start/AppIdentityConfig.cs
andIdentityModels
文件从复制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
方法的第一行遇到异常:
值不能为空。参数名称:上下文
Microsoft.AspNet.Identity.EntityFramework.dll 中出现“System.ArgumentNullException”类型的异常,但未在用户代码中处理
以下是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)
{
}
}
这个异常的原因可能是什么以及如何解决这个问题?