如何创建一个ASP.NET成员资格表的用户,而不使用CREATEUSER [英] How can I create users in a ASP.NET membership table without using CreateUser

查看:150
本文介绍了如何创建一个ASP.NET成员资格表的用户,而不使用CREATEUSER的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从现有的论坛,我使用一个ASP.NET成员资格表,而无需使用CREATEUSER迁移用户和帖子。基本上我想要保持用户ID,这样,当我迁移岗位,他们继续与正确的用户相关联。有没有办法做到这一点还是我会过得更好只是用CREATEUSER,然后寻找一种方法来重新分配后按用户ID为正确的新的ID?

I want to migrate users and posts from an existing forum I am using to a ASP.NET membership table without using CreateUser. Basically I want to maintain userIDs so that when I migrate posts they continue to associate with the correct users. Is there a way to do this or would I be better off just using CreateUser and then finding a way to re-assign the post-by-UserIDs to the correct new IDs?

感谢

推荐答案

您可以创建一个可以使用来自用户表加入到后您的表中的用户配置表。这将从ASP.NET成员资格提供程序的内部隔离你,可以为更多的用户信息的扩展点。

You could create a UserProfile table that you can use to join from the User table to your Post table. This will insulate you from the ASP.NET Membership Provider's internals and can be an extension point for additional user information.

下面是一个存储过程,我用它来创建新用户和他们的个人资料相关联的功能:

Here's a stored procedure and associated functions that I use to create new users and their profiles:

CREATE PROCEDURE [dbo].[CreateUser] 
  @UserName nvarchar(256)
, @ClearTextPassword nvarchar(128)
, @Email nvarchar(256)
, @PostingID uniqueidentifier

AS

BEGIN

DECLARE @ApplicationName nvarchar(256)
DECLARE @PasswordFormat int
DECLARE @UnencodedSalt uniqueidentifier
DECLARE @Password nvarchar(128)
DECLARE @PasswordSalt nvarchar(128)
DECLARE @Now DATETIME
DECLARE @UniqueEmail int

SET @ApplicationName = 'YOUR_APPLICATION_NAME'
SET @PasswordFormat = 1 
SET @UnencodedSalt = NEWID()
SET @PasswordSalt = dbo.base64_encode(@UnencodedSalt)
SET @Password = dbo.base64_encode(HASHBYTES('SHA1', 
   CAST(@UnencodedSalt as varbinary(MAX)) 
   + CAST(@ClearTextPassword AS varbinary(MAX)) )) 
SET @Now = getutcdate()
SET @UniqueEmail = 1


BEGIN TRANSACTION

DECLARE @UserId uniqueidentifier

EXECUTE [dbo].[aspnet_Membership_CreateUser] 
   @ApplicationName
  ,@UserName
  ,@Password
  ,@PasswordSalt
  ,@Email
  ,NULL
  ,NULL
  ,1
  ,@Now
  ,@Now
  ,@UniqueEmail
  ,@PasswordFormat
  ,@UserId OUTPUT

INSERT INTO [dbo].[UserProfile]
(
 [UserID]
,[PostingID]
)
VALUES
(
 @UserId
,@PostingID
)

COMMIT  

CREATE FUNCTION [dbo].[base64_decode] 
(@base64_text VARCHAR(max)) 
RETURNS VARBINARY(max)

WITH SCHEMABINDING, RETURNS NULL ON NULL INPUT

BEGIN

DECLARE @x XML; SET @x = @base64_text 
RETURN @x.value('(/)[1]', 'VARBINARY(max)')

END

CREATE FUNCTION [dbo].[base64_encode] 
(@data VARBINARY(max)) 
RETURNS VARCHAR(max)

WITH SCHEMABINDING, RETURNS NULL ON NULL INPUT

BEGIN

RETURN (

SELECT [text()] = @data 
FOR XML PATH('')

) 
END

这篇关于如何创建一个ASP.NET成员资格表的用户,而不使用CREATEUSER的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆