We have used Membership earlier and now in the new project we are using Identity for authentication and authorization. We are able to create users and role programmatically (in Seed method of Identity project). We also need to link these membership user to application user e.g Employee while creating users in Seed method of application DAL. For which earlier we had used SQL Script. Now similar SQL Script we need to write to create Identity users and roles. From SQL Script we could grab MembershipId for user and use this MembershipId value to assign it Employee's MembershipId column.
The problem we are stuck at is, the stored procedures e.g. "aspnet_Membership_CreateUser" which was available in Membership DB (aspnetdb), not available in Identity DB we created.
The script looks like below:
-- Create roles for 'XXX' Application
EXEC [aspnet_Roles_CreateRole] 'XXX','ADMIN'
EXEC [aspnet_Roles_CreateRole] 'XXX','USER'
-- Create new membership user
EXEC @return_value = [dbo].[aspnet_Membership_CreateUser]
@ApplicationName = N'XXX',
@UserName = N'[email protected]',
@Password = N'QhoM803ew/sdfdf/4NQ=',
@PasswordSalt = N'dGzG1ddfdfdfk1Kqwddff==',
@Email = N'[email protected]',
@PasswordQuestion = N'secretQuestion',
@PasswordAnswer = N'secretAnswer',
@IsApproved = true,
@CurrentTimeUtc = @nowUtc,
@CreateDate = @now,
@UniqueEmail = 1,
@PasswordFormat = 1,
@UserId = @MembershipId_OrgAdmin OUTPUT
PRINT 'Test Admin Created successfully.'
-- Assign role to user
EXEC [aspnet_UsersInRoles_AddUsersToRoles]
@ApplicationName = N'XXX',
@UserNames = N'[email protected]',
@RoleNames = N'ADMIN',
@CurrentTimeUtc = @nowUtc
PRINT 'Test Admin assigned to ADMIN Role successfully.'
-- Finally create a application user and connect it to membership user
INSERT INTO OrganizationUser
(MembershipId,IsDeleted,FirstName,LastName,PhoneNumber,Extension,Address1,Address2,City,State,ZipCode,Country,JobTitle,IsActive,OrganizationId,IsPasswordReset,DownloadCode,IsContactPerson,LastLoginDate,WelcomeEmailDate,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy)
VALUES
(@MembershipId_OrgAdmin,0,'XXX','Admin','2888262','800','ABC','Charlotte, SC 21270','SC','SC','21270','US','XXX Admin',1,(select OrganizationId from Organization where Name='XXX'),0,'1-1-14110985',1,null,null,@now,null,@now,null)
Question:
- Does these stored procedure exist in Identity?
- What are the possible/suggested ways to deal with this situation i.e. link membership user with application user using Identity?