WebSecurity - ConfirmAccount ()


❮ Bảo mật Web

Sự định nghĩa

Phương thức ConfirmAccount () xác nhận và kích hoạt tài khoản bằng mã xác nhận.


Cú pháp C # và VB

WebSecurity.ConfirmAccount(accountConfirmationToken)

Các ví dụ

Ví dụ 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";
    }
}

VB ví dụ

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

Thông số

Parameter Type Description
accountConfirmationToken String The confirmation tokene

Giá trị trả lại

Type Description
Boolean  true if the account is confirmed, otherwise false.

Lỗi và ngoại lệ

Bất kỳ quyền truy cập nào vào đối tượng WebSecurity đều ném ra một lỗi không hợp lệ nếu:

  • Phương thức InitializeDatabaseConnection () chưa được gọi
  • SimpleMembership không được khởi tạo (hoặc bị vô hiệu hóa trong cấu hình trang web)

Nhận xét

Mã thông báo xác nhận có thể được tạo bằng các phương thức CreateAccount () , CreateUserAndAccount () hoặc GeneratePasswordResetToken () .

Quy trình phổ biến là gửi mã thông báo đến người dùng trong email và yêu cầu người dùng xác minh danh tính (thông qua liên kết đến trang xác nhận).


❮ Bảo mật Web