Adds a new user with specified property values and a unique identifier to the data store and returns a status parameter indicating that the user was successfully created or the reason the user creation failed.
Namespace:
System.Web.Security
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Shared Function CreateUser ( _
username As String, _
password As String, _
email As String, _
passwordQuestion As String, _
passwordAnswer As String, _
isApproved As Boolean, _
providerUserKey As Object, _
<OutAttribute> ByRef status As MembershipCreateStatus _
) As MembershipUser
Dim username As String
Dim password As String
Dim email As String
Dim passwordQuestion As String
Dim passwordAnswer As String
Dim isApproved As Boolean
Dim providerUserKey As Object
Dim status As MembershipCreateStatus
Dim returnValue As MembershipUser
returnValue = Membership.CreateUser(username, _
password, email, passwordQuestion, _
passwordAnswer, isApproved, providerUserKey, _
status)
public static MembershipUser CreateUser(
string username,
string password,
string email,
string passwordQuestion,
string passwordAnswer,
bool isApproved,
Object providerUserKey,
out MembershipCreateStatus status
)
public:
static MembershipUser^ CreateUser(
String^ username,
String^ password,
String^ email,
String^ passwordQuestion,
String^ passwordAnswer,
bool isApproved,
Object^ providerUserKey,
[OutAttribute] MembershipCreateStatus% status
)
public static function CreateUser(
username : String,
password : String,
email : String,
passwordQuestion : String,
passwordAnswer : String,
isApproved : boolean,
providerUserKey : Object,
status : MembershipCreateStatus
) : MembershipUser
CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. If the user creation fails, you can retrieve a MembershipCreateStatus value from the status output parameter that indicates why user creation failed. You can specify a unique identifier for the user, such as a primary key value for a database, by using the providerUserKey parameter.
The CreateUser method will return nullNothingnullptra null reference (Nothing in Visual Basic) if password is an empty string or nullNothingnullptra null reference (Nothing in Visual Basic), username is an empty string or nullNothingnullptra null reference (Nothing in Visual Basic) or contains a comma (,), passwordQuestion is not nullNothingnullptra null reference (Nothing in Visual Basic) and contains an empty string, or passwordAnswer is not nullNothingnullptra null reference (Nothing in Visual Basic) and contains an empty string.
Once a membership user has been created and you have a reference to a MembershipUser object for that user, you can modify the settings for that user with the MembershipUser public methods and by setting the property values of the MembershipUser object and then passing the MembershipUser object to the UpdateUser method.
If a user already exists in the data source for the application, you can obtain a MembershipUser object for the existing user with the GetUser method.
Leading and trailing spaces are trimmed from all string parameter values.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources