创建管理员用户后,当前控制器出现问题。这是用于创建管理员用户的代码: protected override void Initialize(RequestContext requestContext) { using (var ac = new ApplicationDbContext()) { var userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(ac)); var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(ac)); var user = new ApplicationUser { UserName = "hello@gmail.com", Email = "hello@gmail.com" }; userManager.Create(user, "Hello1234!"); roleManager.Create(new IdentityRole("admin")); user = userManager.FindByNameAsync(user.UserName).Result; userManager.AddToRole(user.Id, "admin"); } }由于错误而更新当我导航到产品控制器时,在浏览器中出现此错误:Server Error in '/' Application.Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
1 回答
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消