Export (0) Print
Expand All

Membership.CreateUser Method (String, String, String)

Adds a new user with a specified e-mail address to the data store.

Namespace: System.Web.Security
Assembly: System.Web (in system.web.dll)

public:
static MembershipUser^ CreateUser (
	String^ username, 
	String^ password, 
	String^ email
)
public static MembershipUser CreateUser (
	String username, 
	String password, 
	String email
)
public static function CreateUser (
	username : String, 
	password : String, 
	email : String
) : MembershipUser
Not applicable.

Parameters

username

The user name for the new user.

password

The password for the new user.

email

The e-mail address for the new user.

Return Value

A MembershipUser object for the newly created user.

Exception typeCondition

MembershipCreateUserException

The user was not created. Check the StatusCode property for a MembershipCreateStatus value.

CreateUser adds a new user to the data store and returns a MembershipUser object for the newly created user. If the user creation fails, a MembershipCreateUserException is thrown. You can retrieve a MembershipCreateStatus value from the StatusCode property of the MembershipCreateUserException that indicates why user creation failed.

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, such as ChangePasswordQuestionAndAnswer for applications where RequiresQuestionAndAnswer is true, or by setting the property values of the MembershipUser object and passing them 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 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 (Visual Studio).

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft