I have blogged previously about Identity and will continue to do so because I think it is a powerful and easy to use package for user and role management. The one thing that it is missing from the base install is a web based method for an administrator to manage those users and roles. There is a nuget package that I have used and talked about before called the IdentitySample. This package very easy to install; however, the problem is that it changes the namespace of over 30 different files. It will also completely wipe out any code on the shared layout as well as the home index file unless you step through and approve or disallow identity to change every file individually.
I don’t understand why the IdentitySample was created to modify so many files when it appears that there is no reason. I have also tried to do a simply find and replace to update the IdentitySample namespace to the namespace of my project with disastrous results. Because of all of this I got tired of the hassle and created my own alternative to the IdentitySample that will initialize the DB, add a default administrator and provide user and role management but without all the extra unnecessary file modifications.
You can download the CustomIdentityManagement project from my GitHub repository at https://github.com/jpresley/CustomIdentityManagement. I created it to be primarily drag and drop but there is some minor configuration involved as shown below (also explained in the project ReadMe).
- Once the project is downloaded and unzipped you simply have to copy the following files into their respective locations
- Copy the UsersAdmin and RolesAdmin folder to the Views folder
- Copy the IdentityManagement folder to the root of the web project
- At this point you can find and replace all instances of CustomIdentityManagement with the name of your web project so that all of the namespaces are consistent.
- Next you will want to open the IdentityInitializer.cs file and update the default admin email and password at the top of the class from the default for security purposes.
- Finally you will need to add the following code to the ConfigureAuth(IAppBuilder app) method of the App_Start/Startup.Auth.cs file below the other app settings.
Once those configuration steps are complete you can initialize the project.
- Ensure that the DefaultConnection in the web.config file is pointing to the desired database
- Run the app and call the InitIdentity controller (domain.com/InitIdentity).
Using the application is very simple and you just have to call the UsersAdmin or RolesAdmin controllers from the root of your domain (domain.com/UsersAdmin or domain.com/RolesAdmin). The rest of Identity operates as normal.