WebSecurity - ConfirmAccount()


WebSecurity 对象WebSecurity Object

Definition

ConfirmAccount()The method uses an account confirmation token to confirm and activate the account.


C# and VB Syntax

WebSecurity.ConfirmAccount(accountConfirmationToken)


Example

Example C#

string message = "";
var confirmationToken = Request["confirmationCode"];

WebSecurity.Logout();

if (!confirmationToken.IsEmpty())
{
    if (WebSecurity.ConfirmAccount(confirmationToken))
    {
    message = "Registration confirmed";
    }
    else
    {
    message = "Could not confirm your registration";
    }
}

Example VB

message = ""
confirmationToken = Request("confirmationCode")

WebSecurity.Logout()

if !confirmationToken.IsEmpty() then
   if WebSecurity.ConfirmAccount(confirmationToken) then
       message = "Registration Confirmed"
    else
       message = "Could not confirm your registration"
    end if
end if


Parameters

Parameter Type Description
accountConfirmationToken String Account confirmation token


Return Value

Type Description
Boolean If the account is confirmed, returnstrue, otherwise returnsfalse。


Errors and Exceptions

In the following cases, anyWebSecurityaccess to the object will throw anInvalidOperationException:

  • InitializeDatabaseConnection()method has not been called
  • SimpleMembershiphas not been initialized (or is disabled in the website configuration)

Remarks

The account confirmation token can be created by theCreateAccount()、 CreateUserAndAccount()orGeneratePasswordResetToken()method.

The typical process is to send a token to the user in an email, asking the user to verify their identity (via a link to the confirmation page).


Technical Data

Name Value
Namespace WebMatrix.WebData
Assembly WebMatrix.WebData.dll


WebSecurity 对象WebSecurity Object Other Extensions