This documentation is archived and is not being maintained.

Membership::CreateUser Method (String, String, String, String, String, Boolean, MembershipCreateStatus%)

Adds a new user with specified property values 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)

public:
static MembershipUser^ CreateUser(
	String^ username, 
	String^ password, 
	String^ email, 
	String^ passwordQuestion, 
	String^ passwordAnswer, 
	bool isApproved, 
	[OutAttribute] MembershipCreateStatus% status
)

Parameters

username
Type: System::String

The user name for the new user.

password
Type: System::String

The password for the new user.

email
Type: System::String

The e-mail address for the new user.

passwordQuestion
Type: System::String

The password-question value for the membership user.

passwordAnswer
Type: System::String

The password-answer value for the membership user.

isApproved
Type: System::Boolean

A Boolean that indicates whether the new user is approved to log on.

status
Type: System.Web.Security::MembershipCreateStatus%

A MembershipCreateStatus indicating that the user was created successfully or the reason that creation failed.

Return Value

Type: System.Web.Security::MembershipUser
A MembershipUser object for the newly created user. If no user was created, this method returns nullptr.

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.

The CreateUser method will return nullptr if password is an empty string or nullptr, username is an empty string or nullptr or contains a comma (,), passwordQuestion is not nullptr and is an empty string, or passwordAnswer is not nullptr 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.

The following code example creates a new user for an ASP.NET application configured to use forms authentication and ASP.NET membership. If the user is not created successfully, a message is displayed to the user. Otherwise, the user is redirected to the login page for the application.

Security noteSecurity Note:

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

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
Show: