GitHub: Custom Identity Management

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).

  1. 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
  2. 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.
  3. 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.
  4. 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.
app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);

Once those configuration steps are complete you can initialize the project.

  1. Ensure that the DefaultConnection in the web.config file is pointing to the desired database
  2. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s