Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void CreateAdminIfNeeded()
- {
- // Get Admin Account
- string AdminUserName = ConfigurationManager.AppSettings["AdminUserName"];
- string AdminPassword = ConfigurationManager.AppSettings["AdminPassword"];
- string fileName = HttpContext.Server.MapPath(@"~/Images/noImg.png");
- byte[] imageData = null;
- FileInfo fileInfo = new FileInfo(fileName);
- long imageFileLength = fileInfo.Length;
- FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
- BinaryReader br = new BinaryReader(fs);
- imageData = br.ReadBytes((int)imageFileLength);
- // See if Admin exists
- var objAdminUser = UserManager.FindByEmail(AdminUserName);
- if (objAdminUser == null)
- {
- //See if the Admin role exists. In this part I am getting error
- if (!RoleManager.RoleExists("Administrator"))
- {
- // Create the Admin Role (if needed)
- IdentityRole objAdminRole = new IdentityRole("Administrator");
- RoleManager.Create(objAdminRole);
- }
- // Create Admin user
- var objNewAdminUser = new ApplicationUser { UserName = AdminUserName, Email = AdminUserName, UserPhoto = imageData };
- var AdminUserCreateResult = UserManager.Create(objNewAdminUser, AdminPassword);
- // Put user in Admin role
- UserManager.AddToRole(objNewAdminUser.Id, "Administrator");
- }
- }
- #endregion
- //See if the Admin role exists.
- if (!RoleManager.RoleExists("Administrator"))
- {
- // Create the Admin Role (if needed)
- IdentityRole objAdminRole = new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement