WebSecurity.CreateUserAndAccount Method

Creates a new user profile entry and a new membership account.

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

public static string CreateUserAndAccount(
	string userName,
	string password,
	Object propertyValues,
	bool requireConfirmationToken


Type: System.String
The user name.
Type: System.String
The password for the user.
Type: System.Object
(Optional) A dictionary that contains additional user attributes. The default is null.
Type: System.Boolean
(Optional) true to specify that the user account must be confirmed; otherwise, false. The default is false.

Return Value

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


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


The InitializeDatabaseConnection() method was not called.


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 user profile table and then a corresponding entry in the membership table. The ID of the membership entry is based on the ID of the user profile entry. (The IDs of the entries in the two tables match.)

If you are manually maintaining the user profile table and want to create only a membership table entry for the user, call the CreateAccount(String, String, Boolean) method instead.

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.

  • Medium trust for the immediate caller. This member can be used by partially trusted code.