views:

330

answers:

2

Hi folks,

I have used the asp membership feature to add user management to my web app. I have modified the default tables to include a couple more fields. On the create user wizard I have turned wizard step one into a customizable template and have added in the controls for the 2 fields.

Do I know just modify the stored procedure used for storing the users record? how would I add a dropdown list for this?

USE [DataWarehouseClients]
GO
/****** Object:  StoredProcedure [dbo].[aspnet_Users_CreateUser]    Script Date:     04/09/2010 12:03:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[aspnet_Users_CreateUser]
   @ApplicationId    uniqueidentifier,
   @UserName         nvarchar(256),
   @IsUserAnonymous  bit,
   @LastActivityDate DATETIME,
   @UserId           uniqueidentifier OUTPUT
AS
BEGIN
   IF( @UserId IS NULL )
       SELECT @UserId = NEWID()
   ELSE
BEGIN
    IF( EXISTS( SELECT UserId FROM dbo.aspnet_Users
                WHERE @UserId = UserId ) )
        RETURN -1
END

INSERT dbo.aspnet_Users (ApplicationId, UserId, UserName, LoweredUserName, IsAnonymous, LastActivityDate)
VALUES (@ApplicationId, @UserId, @UserName, LOWER(@UserName), @IsUserAnonymous, @LastActivityDate)

RETURN 0

END

Cheers --Billy

A: 

The ASP.NET membership API uses the stored proc aspnet_Users_CreateUser as far as I know

edosoft
thanks i've found the stored proc but im not entirely sure how i can use it. can I just add in the controls i added to the procedure? How would like work with a dropdown box? I've added the procedure to my post.
iamjonesy
I've never directly called this sproc, but always used the API: MembershipUser newUser = Membership.CreateUser(UsernameTextbox.Text, PasswordTextbox.Text, EmailTextbox.Text);
edosoft
@edosoft - did a quick google for the api and came across this article http://msdn.microsoft.com/en-us/library/t8yy6w3h.aspx. maybe i should just forget about the wizard and do it myself!
iamjonesy
+1  A: 

If you use the ASP.Net membership api as @edosoft suggested then you shouldn't need to update the stored procs manually.

If you want to add new/custom fields to a user profile then you can add a key in the web.config file which is associated to a profile. Then the values for this field can be selected separately from a db table of just used from the static dropdown list in a separate routine eg.

In your web.config file:

    <profile enabled="true" defaultProvider="providername" automaticSaveEnabled="true">
        <providers>
          <add name="providername" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ConnectionString" applicationName="AppName"/>
        </providers>
        <properties>
          <add name="UserFirst"/>
          <add name="UserLast"/>
        </properties>
    </profile>

And then you can use it like so where User_ID is a string identifier.

        Membership.CreateUser(User_ID, "password", "[email protected]")        
        Dim objProfile As ProfileCommon = CType(ProfileBase.Create(User_ID, True), ProfileCommon)
        objProfile.UserFirst = User_First
        objProfile.UserLast = User_Last
        objProfile.Save()

Hope this helps.

WestDiscGolf