سلام
بنده یه مشکلی دارم که دو روزه حالمو گرفته!!
کدم توی Seed ارور Object reference not set to an instance of an object که میدونم ارورش چیه ولی هرچی سرچ میکنم و کارایی که میگن بکن رو میکنم ولی جواب نمیگیرم و بازم این ارور رو میده، این کدهامه:
کد استارت آپ:
public partial class Startup { public void ConfigureAuth(IAppBuilder app) { // Configure the db context, user manager and signin manager to use a single instance per request app.CreatePerOwinContext(TicketDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
کد ApplicationUserManager:
public class ApplicationUserManager : UserManager<Personal> { public ApplicationUserManager(IUserStore<Personal> store) : base(store) { } public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) { //khodam userStore //var userStore = new UserStore<Personal>(context.Get<TicketDbContext>()); //return ApplicationUserManager(userStore); var manager = new ApplicationUserManager(new UserStore<Personal>(context.Get<TicketDbContext>())); // Configure validation logic for usernames manager.UserValidator = new UserValidator<Personal>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequiredLength = 4, RequireNonLetterOrDigit = false, RequireDigit = false, RequireLowercase = false, RequireUppercase = false, }; // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user // You can write your own provider and plug it in here. manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<Personal> { MessageFormat = "Your security code is {0}" }); manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<Personal> { Subject = "Security Code", BodyFormat = "Your security code is {0}" }); // Configure user lockout defaults manager.UserLockoutEnabledByDefault = true; manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); manager.MaxFailedAccessAttemptsBeforeLockout = 5; manager.EmailService = new EmailService(); manager.SmsService = new SmsService(); var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider<Personal>(dataProtectionProvider.Create("ASP.NET Identity")); //khodam!!! //{ // TokenLifespan = TimeSpan.FromMinutes(1) //}; } return manager; } }
کد ApplicationRoleManager:
public class ApplicationRoleManager : RoleManager<IdentityRole> { public ApplicationRoleManager(IRoleStore<IdentityRole, string> roleStore) : base(roleStore) { } public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context) { return new ApplicationRoleManager(new ApplicationRoleStore(context.Get<TicketDbContext>())); } }
کد Configuration متد Seed:
private ApplicationUserManager _userManager;
public ApplicationUserManager userManager
{
get { return _userManager ?? HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
private set { _userManager = value; }
}
private ApplicationRoleManager _roleManager;
public ApplicationRoleManager roleManager
{
get { return _roleManager ?? HttpContext.Current.GetOwinContext().Get<ApplicationRoleManager>(); }
private set { _roleManager = value; }
}
و وقتی میخوام Update Database کنم بازم ارور Object reference not set to an instance of an object. میده!!!!
خیلی ممنون میشم کمکم کنید و در آخر خیلی خیلی سایتتون عالیه
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)