aahh... thanks, that's a good one ! This is what I did...
protected void PostRegister_Click1(object sender, EventArgs e)
{
if (!(String.IsNullOrEmpty(UserName.Text) || String.IsNullOrEmpty(RegisterBox.Text)))
{
MembershipUser user = Membership.GetUser(UserName.Text.ToString());
if (user == null)
{
user = Membership.CreateUser(UserName.Text.ToString(), "gendac!@#", RegisterBox.Text.ToString());
user.IsApproved = false;
Membership.UpdateUser(user);
}
else
return; //TODO, error
String email = RegisterBox.Text.ToString();
string link = "http://localhost:32781/" + "Confirmation.aspx?UserID=" + user.ProviderUserKey.ToString(); // TODO: Make dynamic
try
{
//create the mail message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//set the addresses
mail.From = new MailAddress("hugo@gendac.co.za");
mail.To.Add(email);
//set the content
mail.Subject = "Click the link to register.";
mail.Body = link;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1"); // Make dynamic
//to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = new NetworkCredential("hugo", "blaaaaa");
smtp.Send(mail);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
}
}
and then to confirm
public partial class Confirmation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String userKey = (Request.QueryString["UserID"].ToString());
Guid guid = new Guid(userKey);
if (userKey != null)
{
MembershipUser user = Membership.GetUser(guid);
if (user != null)
{
user.IsApproved = true;
Membership.UpdateUser(user);
Message.Text = String.Format("Welcome {0}, you are now registered", user.UserName);
}
else
Message.Text = String.Format("Invalid user ID");
}
}
}
Seems to work fine .... do you guys see any loop holes... ?