Free Controls for User and Role Management in ASP.NET 2.0
September 15th, 2006If 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!
September 18th, 2006 at 12:55 am
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
September 18th, 2006 at 5:49 am
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.
September 19th, 2006 at 5:45 am
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
September 19th, 2006 at 6:26 am
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.
October 6th, 2006 at 11:10 am
Looks great only zip says its corrupted. I am about to write stuff to do this wish the zip would have worked.
October 6th, 2006 at 11:25 am
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.
October 6th, 2006 at 8:37 pm
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!
October 6th, 2006 at 9:04 pm
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.
November 22nd, 2006 at 2:12 am
[...] 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 [...]
May 7th, 2007 at 1:05 pm
[...] read more | digg story [...]
December 1st, 2007 at 7:35 pm
THanks for posting this but why did you leave out a password field when you create a user?
December 1st, 2007 at 7:51 pm
No reason. I simply have the password automatically generated this way but you could change it to allow for the password to be set.