I will tell you the steps on how to Implelment it
- User Registers
- Once registration guid is created
- guid is put into a table associated with a username
- E-Mail is sent to user with a url based on the GUID something like ( http://example.com/Activate.aspx?key=1234-1234-1234 )
- User Opens Email and click link
- Person comes to activation page
- Activation page reads querystring and associates the string with guid in db. If a match executes code to “approve” account for use
- User can login
Using membership it will be more easy
You can use the Create User Wizard Control
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
oncreateduser="CreateUserWizard1_CreatedUser" DisableCreatedUser="true">
<WizardSteps>
<asp:CreateUserWizardStep runat="server" />
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
</div>
The login.aspx.cs will look like this
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
string userName = CreateUserWizard1.UserName;
string emailAddress = CreateUserWizard1.Email;
// Lets get the user's id
Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey;
// Now lets create an email message
StringBuilder emailMessage = new StringBuilder();
emailMessage.Append("Thank you for creating an account with YourDomain.com");
emailMessage.Append("<br />");
emailMessage.Append("Please click the below link to activate your account <br />");
emailMessage.Append(string.Format("<a href='http://www.YourDomain.com/ActivateUser.aspx?userName{0}&Id={1}'>Activate {0} </a>", userName, userId.ToString()));
MailMessage email = new MailMessage();
email.From = new MailAddress("noReply@YourDomain.com");
email.To.Add(new MailAddress(emailAddress));
email.Subject = "Please activate your account with YourDomain";
email.Body = emailMessage.ToString();
email.IsBodyHtml = true;
// Send the email
SmtpClient client = new SmtpClient();
client.Send(email);
// Redirecto to What ever page
Response.Redirect("Default.aspx", true);
}
ActivateUser.aspx.cs : Here, we get the UserId and his email address as QueryString parameters and use membership api to activate the user.
protected void Page_Load(object sender, EventArgs e)
{
// Lets Activate the User
if (String.IsNullOrEmpty(Request.Params["Id"]))
{
// We do not have the userId. Redirect some where
Response.Redirect("ErrorPage.aspx");
}
else
{
// We have a userId.
try
{
Guid userId = new Guid(Request.Params["Id"]);
MembershipUser user = Membership.GetUser(userId);
// Activate the user
user.IsApproved = true;
// Update the user activation
Membership.UpdateUser(user);
// We success fully activate the user. Redirect somewhere
Response.Redirect("Welcome.aspx", true);
}
catch
{
// Error. Redirect some where
Response.Redirect("ErrorPage.aspx");
}
}
// We should never reach here. Just in case redirect some where
Response.Redirect("Default.aspx", true);
}
Refer this link also
http://ctrlf5.net/?p=55
Regards