1
我試圖在aspnet樣板文件中使用Identity實現忘記密碼。在aspnet樣板文件中實現忘記密碼
- 我與個別用戶身份驗證Visual Studio創建一個新項目,實施和測試忘記密碼的功能(項目名稱:
IdentityProject
)。 - 然後我下載了abp項目並將
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
方法的第一行越來越例外:
值不能爲空。參數名:上下文
類型「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)
{
}
}
可能是什麼這個異常的原因,以及如何解決這個問題?
請讓我知道,如果我的問題不明確。 –