protected void CreateStudentUser() { string fname = txtFirstname.Text.Trim(); string mname = txtMiddlename.Text.Trim(); string lname = txtLastname.Text.Trim(); string email = txtEmail.Text.Trim(); string username = txtUserName.Text.Trim(); string passW1 = txtPassword1.Text.Trim(); string confirPwd = txtPassConfirmed.Text.Trim(); string activationCode = Guid.NewGuid().ToString(); int gender = Convert.ToInt32(Session["gender"].ToString()); string admNo = txtIDorRegNo.Text.Trim(); string passEncrypt = EncryptP(confirPwd); DateTime doB; var leohii = DateTime.Today; var dofB = dateofBirth.Value.Trim(); if (string.IsNullOrWhiteSpace(dofB)) { KCDFAlert.ShowAlert("Select a valid date!"); dateofBirth.Focus(); return; } else { doB = DateTime.Parse(dofB); } if (string.IsNullOrEmpty(fname) || string.IsNullOrEmpty(lname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(username) || string.IsNullOrEmpty(passW1) || string.IsNullOrEmpty(confirPwd)) { lblError.Text = "Please fill all the empty required fields!"; return; } if (passW1 != confirPwd) { lblError.Text = "Password Mismatch, try again!"; KCDFAlert.ShowAlert("Password Mismatch, try again!"); txtPassword1.Text = ""; txtPassConfirmed.Text = ""; } else { try { var credentials = new NetworkCredential(ConfigurationManager.AppSettings["W_USER"], ConfigurationManager.AppSettings["W_PWD"], ConfigurationManager.AppSettings["DOMAIN"]); Portals sup = new Portals(); sup.Credentials = credentials; sup.PreAuthenticate = true; if (sup.FnCreateAccount(fname, mname, lname, email, username, passEncrypt, activationCode, gender, doB, admNo)) { this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "getmeTohomeConfirm()", true); //call goback to login to load Default page for user InsertToActivationDB(username, activationCode); using (MailMessage mm = new MailMessage("*****@*****.**", email)) { string ActivationUrl = string.Empty; ActivationUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Activated.aspx?ActivationCode=" + activationCode + "&username="******""; //Click here to activate your account //var contactUsUrl = Page.ResolveClientUrl("~/Account/Register.aspx"); mm.Subject = "KCDF Account Activation"; string body = "Hello " + username + ","; body += "<br /><br />Please click the following link to activate your account"; // body += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("/Account/Register.aspx", "/Account/Activated.aspx?ActivationCode=" + activationCode) + "'>Click here to activate your account.</a>"; body += "<br />" + ActivationUrl + ""; body += "<br /><br />Thanks"; mm.Body = body; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "Kcdfportal@4321*~"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); // KCDFAlert.ShowAlert("Activation link has been send to your email"); } } } catch (Exception ex) { lblError.Text = ex.Message; return; } } }