如何在SQL表中引用成员资格提供者用户?

时间:2009-05-26 06:40:24

标签: asp.net membership-provider

当我创建SQL表并且我想在ASP.NET中引用成员资格提供程序用户时,我使用什么类型的字段以及如何从用户那里获取值?

1 个答案:

答案 0 :(得分:4)

在SQL Server中,您将使用UNIQUEIDENTIFIER作为列类型并将其映射到 [dbo]。[aspnet_Users]。[UserId] 。假设您在ASP.Net应用程序中使用默认的SqlMembership。要在C#中获取登录用户的UserId,您可以使用:

MembershipUser mu = Membership.GetUser();  // This gets the CURRENTLY logged in user.
MembershipUser mu = Membership.GetUser("username");  // This gets the user with username username.
// Obviously you'd use only one of the above 2 lines, otherwise you'd get an error about mu being declared twice.
Guid currentUserId = (Guid)mu.ProviderUserKey;