Tuesday, June 30, 2009

ASP.NET Utility to create SQL Server Database for Membership and Roles Management

Ok, ok. I always forget so to save me some time, here it is...

Open up command line from Visual Studio, then run... cmd>aspnet_regsql.exe

Then execute the following...

-- Register Application
EXEC dbo.aspnet_Applications_CreateApplication 'AppName', NULL

-- Check if Application was registered
SELECT * FROM dbo.aspnet_Applications

-- Create a Role
EXEC dbo.aspnet_Roles_CreateRole 'AppName', 'Administrator'

-- Check if Role was created
SELECT * from dbo.aspnet_Roles

-- Add myself as Admin
DECLARE @Date AS DATETIME
SET @Date = (SELECT GETDATE())
EXEC aspnet_UsersInRoles_AddUsersToRoles 'AppName', 'DOMAIN\username', 'Administrator', @Date

-- Check if I got added as Admin
EXEC dbo.aspnet_UsersInRoles_GetUsersInRoles 'AppName', 'Administrator'

2 comments:

Anonymous said...

It would be nice if you also howed how this relates to web.config

Sincerley T.Saxeggen

Anonymous said...

One way to use roles in web.config:

If http://www.service.com/
But don't want all users to connecto to http://www.service.com/Proceed