• subscribe
October 26, 2006 12:00 AM

Making the Most of Login Controls with ASP.NET

ASP.NET lets you use Visual Studio login controls to simplify Web-site membership administration chores
SQL Server Pro
InstantDoc ID #93053
Downloads
93053.zip

The code for the PopulateUsersInRole procedure at callout B uses a SqlCommand object (cmd1) to reference the aspnet_UsersInRoles_GetUsersInRoles stored procedure within the aspnetdb database. The aspnet_regsql.exe tool automatically populates the database with the stored procedure. The stored procedure requires two parameters, one for the name of the application represented by cstAppName and the other for the name of a role, which is passed to the procedure from the selection in the lbAllRoles ListBox control. The PopulateUsersInRole procedure recovers the usernames in the selected role by iterating through the rows of a SqlDataReader based on the cmd1 SqlCommand. These names are added to the Items collection of the lbUsersInRole ListBox control within a While...End While statement.

The other ListBox controls on the Web form page in Figure 3 are populated with code similar to Listing 2. Of course, the names of the referenced stored procedures change. Some of these stored procedures simply return values, but others let you add and delete users and roles.The code to add a user to a role uses the aspnet_UsersIn-Roles_AddUsersToRoles stored procedure. You can explore all the stored procedures in the aspnetdb database with the help of Server Explorer in Visual Studio 2005 or SQL Server Management Studio.

Why Use Login Controls?
Login controls offer powerful, easy-to-use features for managing membership and role services at an ASP.NET Web site. In many cases, you can achieve useful functionality just by dragging one or more login controls to a Web form. In other cases, simple ADO.NET code lets you take advantage of automatically created stored procedures for managing membership services.

ASP.NET automatically uses a SQL Server Express database file in a Web site to manage membership services in coordination with login controls. Configuring one or more Web sites to use a single SQL Server database simplifies the management of membership services.



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here