The membership framework does not have built-in e-mail verification functionality. Use following steps to activate user account by confirming with an email.
I assume that you have already created your membership database and have a working smtp server that can send emails.
Step 1 : Store user in database as unapproved.
We register the new user as usual and set isApproved value to false. This indicates that the user is on the database but is inactive and cannot log in (until we verify user e-mail).
Membership.CreateUser(txtUserName.Text, txtPassword.Text,txtEmail.Text, “question”,se, out status);
Step 2 : Send Verification Email.
we send an email to the new user with link on how to verify their account.
When the user clicks on the Register button create user account then pass guid to the link as query string parameter.
Button Register OnClick Event :
protected void btnRegister_Click(object sender, ImageClickEventArgs e)
MembershipUser User = Provider.CreateUser(username, password, email, pwQuestion, pwAnswer, false, null, out createStatus);
// The user was created successfully, send the verification e-mail.
Guid guid = (Guid)user.ProviderUserKey;
StringBuilder Message = new StringBuilder();
Message.Append(“Thank you for creating an account with us”);
Message.Append(“Please click the below link to activate your account”);
Message.Append(string.Format(“Activate “, userName, userId.ToString()));
MailMessage email = new MailMessage();
email.From = new MailAddress(“admin@YourDomain.com”);
email.Subject = “Email Verification “;
email.Body = Message.ToString();
email.IsBodyHtml = true;
// Send the email
SmtpClient Emailclient = new SmtpClient();
Step 3 : Verification of Email link
This is last step and we are ready to go live! Now we should receive the request and verify that the GUID is the right one.
// Activate the User
// We do not have the userId.
lblMsg.Text=”We do not have the userId.”;
Guid userId = new Guid(Request.Params[“Id”]);
MembershipUser user = Membership.GetUser(userId);
// Activate the user
user.IsApproved = true;
// Update the user activation
lblMsg.Text = “We successfully activate the user.”;
// Error. Redirect some where
lblMsg.Text = “something went wrong.”;
Here, we get the UserName and his guid as QueryString parameters and use membership api to activate the user.
And that’s it, your are now all set to activate users via Email Message.
Do please send your comments . I would be happy to hear from you.
Thank you , Happy Coding !