Export (0) Print
Expand All

WebSecurity::CreateAccount Method

Creates a new membership account using the specified user name and password and optionally lets you specify that the user must explicitly confirm the account.

Namespace:  WebMatrix.WebData
Assembly:  WebMatrix.WebData (in WebMatrix.WebData.dll)

public:
static String^ CreateAccount(
	String^ userName, 
	String^ password, 
	bool requireConfirmationToken
)

Parameters

userName
Type: System::String
The user name.
password
Type: System::String
The password.
requireConfirmationToken
Type: System::Boolean
(Optional) true to specify that the account must be confirmed by using the token return value; otherwise, false. The default is false.

Return Value

Type: System::String
A token that can be sent to the user to confirm the account.

ExceptionCondition
MembershipCreateUserException

username is empty.

-or-

username already has a membership account.

-or-

password is empty.

-or-

password is too long.

-or-

The database operation failed.

InvalidOperationException

The SimpleMembershipProvider::Initialize(String, NameValueCollection) method was not called.

-or-

The InitializeDatabaseConnection() method was not called.

-or-

The SimpleMembershipProvider membership provider is not registered in the configuration of your site. For more information, contact your site's system administrator.

This method creates a new entry in the membership table of the membership database. It presumes that matching user information (represented by userName) already exists in the user profile table. (To create a new user in both the membership table and in the user profile table, use the CreateUserAndAccount(String, String, Object, Boolean) method.) When you call this method, the membership system verifies that a user profile record exists that matches the name that you pass in username. (The method queries the table that you specified in the userTableName parameter and the column specified in the userNameColumn column when you called the InitializeDatabaseConnection() method in order to initialize membership.) It then creates a new entry in the membership table, using the user ID of the corresponding record in the user profile table.

You can pass true for requireConfirmationToken in order require that the user account must be confirmed by the user. To confirm the account, you get the token as the return value from this method. You then send an email message to the user that contains a link whose URL contains the token. When the user clicks the link, the request is sent to your application, where you extract the token from the link and then call the ConfirmAccount(String) method.

For an example of how to create a new user account by using the CreateAccount(String, String, Boolean) method, how to create a link that contains the confirmation token, and how to email the link to the user, see the Register.cshtml file in the Starter Site template.

For an example of how to use the confirmation token, see the Confirm.cshtml file in the Starter Site template.

  • Medium trust for the immediate caller. This member can be used by partially trusted code.
Show:
© 2014 Microsoft