|   Register
Monday, December 01, 2008   
You are here :     Blog
Membership API
Location: BlogsKing Wilder's Blog    
Posted by: kwdnnsuper 6/13/2007

WHY NOT USE THE ASP.NET 2.0 CONTROLS?

The built-in ASP.NET 2.0 controls are fine for public facing pages that allow your customers to login and create their own account and change passwords, etc.  This application does not do that.  It allows you as an Administrator of the site, to manage (or create) users and roles.  This is something that the public should not be able to do and this application extends the capabilities a bit more to help admins manage their sites.

I've found that when I build a web site application for a client, it will always have an Admin site to manage the site.  Generally I also need to manage the Users and Roles for the site. 

First, there is no built-in interface to manage Roles, so you have to build one.  Second, I've found that I don't have complete control over the User and Role management the way I need it and this also makes it easier for my clients who will end up managing the application themselves.  I don't like to use the ASP.NET Configuration Tool in Visual Studio 2005, especially since my client will not have access to it.

So this is a pretty comprehensive Membership system that allows you to manage users and roles for a system.

QUICK TEST RUN

To quickly see how this application works, after you unzip the file, simply open the application in Visual Studio 2005 and make appropriate modifications to the web.config file to point to the Membership and Roles providers you are working with.  (See below for more web.config settings) 

After the web.config is pointing to you Membership and Roles providers, simply run the application.

INSTALLATION INTO YOUR DEVELOPMENT APPLICATION

Unzip the zip file to a directory of your choice.  It should NOT be unzipped into the ASP.NET application you will be using it in.  You'll see why later.  For now, just unzip it somewhere that will allow you to copy the files to any application you want.

First off, again, this application was built to be used in an Admin site to a public facing site.  It is not intended to be used for public membership creation and/or management.  The standard ASP.NET 2.0 controls are good for that.

To install this into an application that you are working on, simply copy the files into their respective folders.

Example:

\App_Code\HyperLinkPager.cs
\Controls\CreateUsersControl.ascx
\Controls\ManageRolesControl.ascx
\Controls\ManageUsersControl.ascx
\Admin\CreateUser.aspx
\Admin\Default.aspx
\Admin\ManageRoles.aspx
\Admin\ManageUsers.aspx
\[Your folder of choice]\MembershipStyles.css
\Web.sitemap
\web.config

WEB.CONFIG MODIFICATIONS

This example is using a custom Membership and Role providers (MyMembershipProvider, MySqlRoleProvider). It's completely up to you on what attributes you place in the Membership provider.  You can use these or change them as you deem fit.

<system.web>
    <rolemanager enabled="true" defaultprovider="MySqlRoleProvider">
      <providers>
        <add name="MySqlRoleProvider" 
            type="System.Web.Security.SqlRoleProvider" 
            connectionstringname="LocalSqlServer" 
            applicationname="MyApp" />
      </providers>
    </rolemanager>
    <membership defaultprovider="MyMembershipProvider">
      <providers>
        <clear />
        <add name="MyMembershipProvider" 
            type="System.Web.Security.SqlMembershipProvider" 
            connectionstringname="MyConnection" 
            applicationname="MyApp" 
            requiresquestionandanswer="false" 
            requiresuniqueemail="true" 
            minrequirednonalphanumericcharacters="0" 
            minrequiredpasswordlength="5" />
      </providers>
    </membership>
</system.web>

CONNECTION STRINGS 

In my example I have installed the ASP.NET membership database objects in the same SQL Server database as the application I'm working on, not in the default ASPNETDB.mdf.  I did this for more control.  You don't have to do this, you can use the automatic ASPNETDB database, you'll need to remove the LocalSqlServer element in the Connection String element.

If you end up moving the ASPNETDB files into your own database, you'll need to include the Clear element and re-add the LocalSqlServer connection for the ASPNET files.

<connectionstrings>
    <clear />
    <add name="MyConnection" 
      connectionstring="Data Source=(local); 
    	Database=MyDatabase; 
    	User ID=myUser; 
    	Password=12345;" 
    	providername="System.Data.SqlClient" />
    <add name="LocalSqlServer" connectionstring="Data Source=(local); 
    	Database=MyDatabase; 
    	User ID=myUser; 
    	Password=12345;" 
    	providername="System.Data.SqlClient" />
</connectionstrings>

That's it!

You are free to enhance or change this any way that you need.

If you have any questions or problems, you can post them in my Forum. 

You can download the Membership API application from the Downloads page.

Here are some screen shots of the Membership API that I've integrated into a clients project I'm currently building.

Copyright ©2007 King Wilder
Permalink |  Trackback

Comments (7)   Add Comment
Yet another tweak    By Andy C on 8/5/2007
I notice in the screen shots you have an admin section for content management. Just curious about what you added as I'm looking at adding some myself.

Re: Membership API    By King Wilder on 8/7/2007
Are you talking about what I added to the Membership API or the admin console?

If about the Membership API, I just built a little set of user controls that you can just drop into your application to manage users based on the ASP.NET 2.0 Membership classes.

If you're talking about the admin console, it's a screen shot of a custom e-commerce application I'm working on for a client. It not so much a content management console as much as an Order System. Like the back-end of Commerce Starter Kit (or dashCommerce), it helps the admin manage the orders, products and other aspects of their e-commerce site.

I hope that answered your question.

Re: Membership API    By Andy C on 8/9/2007
In the admin screen, you have a menu section called 'Content Management' with a 'Manage' sublink. I wondered if you'd extended the CSK's ability to handle rich content beyond the current in-place editing. Thanks.

Re: Membership API    By King Wilder on 8/9/2007
Oh, that. Actually when I created that, I was, in fact, creating a CMS type system for the application, but then I figured out how to use the inline Paragraph control used in CSK and I'm using that instead. So this screen shot is old. I'm not actually using the Manage function now. Sorry. :^/

Re: Membership API    By Andy C on 8/12/2007
Drat and double drat. I might actually have to write some code instead of lifting it off forums and blogs!

Re: Membership API for MySql    By King Wilder on 8/21/2007
If you are writing an ASP.NET 2.0 app for MySql, I ran across a great Membership provider for MySql written by Jacques Snyman in CodeProject. It saved me literally a couple days worth of work and it works with my front-end UI.

You can find his CodeProject page at http://www.codeproject.com/aspnet/MySQLsuite.asp.

Tell him King sent you. :^)

kabonfootprint    By kabonfootprint on 9/11/2008
nice.. great job... thanks kabonfootprint


Your name:
Title:
Comment:
Add Comment   Cancel 
King's Blog
King's Blog
King's Blog

Copyright 2007 by King Wilder   |  Privacy Statement  |  Terms Of Use