Free Controls for User and Role Management in ASP.NET 2.0

September 15th, 2006

If you have deployed an ASP.NET 2.0 website with the Membership and Role providers you have had to find a way to manage the users. For a small site you want something which is a simple drag and drop approach. Unfortunately the website adminstration feature you get with Visual Studio will not remotely run on ASP.NET websites hosted on IIS, so you will want some controls to do that. The Login Controls as a part of ASP.NET 2.0 provide for commonly used activities you need on the public side of the website, but nothing has been provided by Microsoft to manager users and roles. I have packaged up a few simple User Controls to do just that.

Below are the instructions to get started, from configuring the providers to testing out the controls.

Configuration

First I will assume you already have your providers configured. Your Web.config would look like this...

Automatic Setup

The next step to run a managed website is to create your first user and place it into an Admin role. That is tricky because you would normally want your Admin functionality to be protected. To have this done automatically you can place the following code in your Global.asax.

That bit of code will ensure that your required roles and an Admin user is created with a fresh website and database.

Controlling Access

Next, lock down the Admin folder so that only users in the Admin role can reach it. The following configuration segment can be added to the bottom of your Web.config just before the closing the configuration element.

The Free Controls

Now you are ready to use the controls to manage users and roles. The User Controls I created are a set of controls I called the Manager Controls.

  • ManagerControl.ascx
  • UserManager.ascx
  • RolesManager.ascx

These User Controls are in the ManagedControls folder underneath the Admin folder. To use them, simply download the Managed Website and try it yourself. It comes pre-configured to talk to a local database called ManagedWebsite over a Trusted Connection, so be sure to set that up before trying to view the site.

Feel free to do whatever you like with this sample website. You will notice that I did not bother to style it in any way. It also only provides the basic functionality of the Membership and Role providers. It does not manage Profile data. What it does do is allow you to create users, edit their bits and assign users to roles.

Enjoy!

12 Responses to “Free Controls for User and Role Management in ASP.NET 2.0”

  1. David Says:

    Hi Brennan,

    I have just finished writing some code to do exactly the same thing so I was interested to see your code. I downloaded the example site but according to Windows the file ManagedWebsite.zip file is invalid or corrupted.

    Can you fix it or am I just unlucky?

    Regards,

    David

  2. brennan Says:

    Try it now. I used WinXP to create the zip file but I have seen this problem before. I think it may be caused by empty folders included in the zip archive, so I have removed the empty App_Data folder. I was able to download and unzip the files.

  3. rachel Says:

    Hi Brennan,
    I downloaded the zip file but when I unzipped it, there was no ManagerControls folder with the user controls on it.

    Regards
    --rachel

  4. brennan Says:

    Try it now. I have no idea why Windows fails to properly create a zip archive anymore. I instead uploaded the files and zipped them on my FreeBSD server.

  5. Randy Says:

    Looks great only zip says its corrupted. I am about to write stuff to do this wish the zip would have worked.

  6. brennan Says:

    Try clearing your cache. Apparently that can be part of the problem. Also try downloading the zip file with Firefox. The file is intact on the server-side.

  7. Randy Says:

    Would only download and run with Firefox for me. Great controls! Saved me hours. Only control I couldn't find was a delete user button? It seems simple to implement one. Was there a reason you didn't?

    Once again thanks!

  8. brennan Says:

    Deleting users can cause problems if you are using the Guid to identify other related data, like the custom profile I described in a blog entry a few after this one. Instead you can lock and unlock an account and keep the user in place.

  9. .NET Developer BS Blogs : User and Role Management in ASP.NET 2.0 Says:

    [...] Verwendet man die ASP.NET Membership und Role Provider sucht man evtl. eine Möglichkeit auf einfache Weise die User und Roles zu verwalten, ohne dieses direkt zu programmieren. Normalerweise kann dies über die ASP.NET Web Site Administration Tool erledigt werden, welches allerdings nach dem deployen der Website nicht mehr zur Verfügung steht. Brennan Stehling hat sich die Mühe gemacht und Control programmiert, die genau für diese Aufgabe gedacht sind. Eine kurze Beschreibung und das Beispielprojekt findet man unter dieser URL. Komischerweise funktioniert der Download des Zip-Archives nur mit FireFox, ansonsten erhält man eine defekte Datei. Eine Anleitung um das Web Seite Administration Tool im Web zu hosten gibt es im Blog von Alex. Veröffentlicht Mittwoch, 22. November 2006 09:00 von BlaBlubBlog Abgelegt unter: Programmierung/.NET/ASP.NET;Programmierung/Visual Studio [...]

  10. mikedopp.com » Blog Archive » Tools for updating asp.net membership tools remotely Says:

    [...] read more | digg story [...]

  11. Chuck Ungar Says:

    THanks for posting this but why did you leave out a password field when you create a user?

  12. Brennan Stehling Says:

    No reason. I simply have the password automatically generated this way but you could change it to allow for the password to be set.