Home Startup.cs Add and Configure User method password issue
Reply: 0

Startup.cs Add and Configure User method password issue

user2024 Published in July 17, 2018, 7:58 am

I have created a method in my Startup.cs file that has the following method in it:


private void createRolesandUsers()
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
            var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));

            // creating first Boss Role and creating a default Boss User    
            if (!roleManager.RoleExists("Boss"))

                // first we create Admin rool   
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "Boss";

                //add a note to get this to rerun?

                //Here we create a Admin super user who will maintain the website                  

                var user = new ApplicationUser();
                user.UserName = "Boss";
                user.Email = "admin@adminaccount.com";

                string userPWD = "Pa$$w0rd";

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin   
                if (chkUser.Succeeded)
                    var result1 = UserManager.AddToRole(user.Id, "Boss");



I then call this method from Configuration. It works great to create the user and the role of Boss. I can confirm the user has been created and also the role when I remotely log into my Azure app's SQL database. Unfortunately, I am unable to log into the account, I have double checked the user name and password and copied and pasted both into the email input and password input. Does any one know what could be wrong with my code to cause this and any suggestions to fix it?

Thank you for your help with this in advance!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30245 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO