Export (0) Print
Expand All

Membership.CreateUser Method (String, String, String, String, String, Boolean, Object, MembershipCreateStatus)

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)

public static MembershipUser CreateUser(
	string username,
	string password,
	string email,
	string passwordQuestion,
	string passwordAnswer,
	bool isApproved,
	Object providerUserKey,
	out 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.

providerUserKey
Type: System.Object

The user identifier for the user that should be stored in the membership data store.

status
Type: System.Web.Security.MembershipCreateStatus

A MembershipCreateStatus indicating that the user was created successfully or the reason 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 null.

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 null if password is an empty string or null, username is an empty string or null or contains a comma (,), passwordQuestion is not null and contains an empty string, or passwordAnswer is not null 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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft