WebSecurity - CreateUserAndAccount()
WebSecurity Object
Definition
CreateUserAndAccount()The method uses a user name and password to create a new account in the user database, and can optionally specify whether the user must explicitly confirm the account.
C# and VB Syntax
Parameters
| Parameters | Type | Description |
|---|---|---|
| userName | String | User name |
| password | String | User password |
| propertyValues | Object | A dictionary that contains extra user attributes |
| requireConfirmation | Boolean | If the account must be confirmed using the token return value, then returntrue. By default returnsfalse。 |
Return Value
| Type | Description |
|---|---|
| String | A token that can be sent to the user for account confirmation. |
Remarks
CreateUserAndAccount()The methodWebSecuritycreates a new entry in the user profile table in the database, and then creates a matching entry in the membership table.
You canrequireConfirmationTokenpass to the parametertruetrue to require that the account must be confirmed by the user. CreateUserAndAccount()Get a token from the method as the return value.
If you want to manually maintain the user profile table and only want to create a membership table entry for the user, callCreateAccount() method.
Errors and Exceptions
In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:
- InitializeDatabaseConnection()The method has not been called.
- SimpleMembershipNot initialized (or disabled in the website configuration).
In the following cases,CreateUserAndAccount()the method also throws anMembershipCreateUserException:
- The user name is empty.
- The user name already has a membership account.
- The password is empty.
- The password is too long.
- The database operation failed.
Technical Data
| Name | Value |
|---|---|
| Namespace | WebMatrix.WebData |
| Assembly | WebMatrix.WebData.dll |
WebSecurity Object Other Extensions