开发者

ASP.NET Create User Wizard - Customisation help

开发者 https://www.devze.com 2022-12-26 00:14 出处:网络
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

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


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@example.com")        
        Dim objProfile As ProfileCommon = CType(ProfileBase.Create(User_ID, True), ProfileCommon)
        objProfile.UserFirst = User_First
        objProfile.UserLast = User_Last
        objProfile.Save()

Hope this helps.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消