than you can write the code oon createduser event.This is the code which i am using in my site.
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
UserBAL objuserBAL = new UserBAL();
MembershipUser username = Membership.GetUser(CreateUserWizard1.UserName);
try
{
// Membership user = Membership.GetUser(CreateUserWizard1.UserName);
//TblUser user1 = new TblUser();
User user1 = new User();
user1.UserName=CreateUserWizard1.UserName;
user1.MembershipUserId = (Guid)username.ProviderUserKey;
CreateUserWizard1.LoginCreatedUser = false;
username.LastActivityDate = System.DateTime.Today.ToUniversalTime();
Membership.UpdateUser(username);
Roles.AddUserToRole(CreateUserWizard1.UserName,"Others");
TextBox tb1 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFirstName");
TextBox tb2 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtLastName");
user1.FirstName = tb1.Text;
user1.LastName = tb2.Text;
//RadioButtonList rdo = (RadioButtonList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("RadioButtonList1");
//if ((rdo.SelectedValue != null )&& (rdo.SelectedValue != "" ))
//{
//user1.UserType = Convert.ToInt32(rdo.SelectedValue);
//}
user1.UserType = 1;
user1.SubscriptionId = 0;
int Result = objuserBAL.InsertUser(user1);
MailMessage msgMail = new MailMessage();
//Net Mail
msgMail.From = new MailAddress(Email);
msgMail.To.Add(CreateUserWizard1.Email);
//msgMail.To.Add("mahajan.namrata@yahoo.com");
////Label lblEmail = (Label)GridView1.Rows[i].FindControl("");
//web Mail
//msgMail.To = "nanuramp@synoris.com";
//msgMail.From =("namratam@synoris.com");
Comman objComman = new Comman();
MailTemplate currenttemplate = new MailTemplate();
currenttemplate = objComman.GetTemplate("ActivationEmail");
//currenttemplate.Body = String.Format(currenttemplate.Body,user1.MembershipUserId.ToString());
//PropertyMapper mapper = new PropertyMapper(user1);
//mapper.MapTemplate(currenttemplate);
//UpdateUI(currenttemplate);
currenttemplate.Body = currenttemplate.Body.Replace("Domain",System.Web.HttpContext.Current.Request.Url.ToString().Replace(System.Web.HttpContext.Current.Request.RawUrl.ToString(), ""));
currenttemplate.Body = currenttemplate.Body.Replace("MembershipUserId", user1.MembershipUserId.ToString());
msgMail.Subject = currenttemplate.Subject;
msgMail.Body = currenttemplate.Body;
// msgMail.Subject = "InvestorScopes Account Activation";
// //msgMail.BodyFormat = MailFormat.Html;
// string emailbody = "Thanks for registration in Investor scopes.To Activate your account click on the following link";
// emailbody += "
// // emailbody += "http://www.google.co.in/";
// emailbody += System.Web.HttpContext.Current.Request.Url.ToString().Replace(System.Web.HttpContext.Current.Request.RawUrl.ToString(), "");
// emailbody += "/RegistrationActive.aspx?ID=";
//// emailbody += "http://www.investorscope.synoris.com/RegistrationActive.aspx?ID=";
// emailbody +=(System.Guid)username.ProviderUserKey;
// emailbody += '"';
// emailbody += ">";
// emailbody += "Activate My Account";
// emailbody += "";
// msgMail.Body = emailbody;
//net mail
msgMail.IsBodyHtml = true;
msgMail.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
//sC.Port = 25;
sC.Credentials = new NetworkCredential(Email, Pwd);
sC.EnableSsl = true;
//SmtpMail.Send(msgMail);
//net mail
sC.Send(msgMail);
emailid = Encryption.Encrypt(user1.UserName);
// msgMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
finally
{
objuserBAL = null;
}
// }
}
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
UserBAL objuserBAL = new UserBAL();
MembershipUser username = Membership.GetUser(CreateUserWizard1.UserName);
try
{
// Membership user = Membership.GetUser(CreateUserWizard1.UserName);
//TblUser user1 = new TblUser();
User user1 = new User();
user1.UserName=CreateUserWizard1.UserName;
user1.MembershipUserId = (Guid)username.ProviderUserKey;
CreateUserWizard1.LoginCreatedUser = false;
username.LastActivityDate = System.DateTime.Today.ToUniversalTime();
Membership.UpdateUser(username);
Roles.AddUserToRole(CreateUserWizard1.UserName,"Others");
TextBox tb1 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFirstName");
TextBox tb2 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtLastName");
user1.FirstName = tb1.Text;
user1.LastName = tb2.Text;
//RadioButtonList rdo = (RadioButtonList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("RadioButtonList1");
//if ((rdo.SelectedValue != null )&& (rdo.SelectedValue != "" ))
//{
//user1.UserType = Convert.ToInt32(rdo.SelectedValue);
//}
user1.UserType = 1;
user1.SubscriptionId = 0;
int Result = objuserBAL.InsertUser(user1);
MailMessage msgMail = new MailMessage();
//Net Mail
msgMail.From = new MailAddress(Email);
msgMail.To.Add(CreateUserWizard1.Email);
//msgMail.To.Add("mahajan.namrata@yahoo.com");
////Label lblEmail = (Label)GridView1.Rows[i].FindControl("");
//web Mail
//msgMail.To = "nanuramp@synoris.com";
//msgMail.From =("namratam@synoris.com");
Comman objComman = new Comman();
MailTemplate currenttemplate = new MailTemplate();
currenttemplate = objComman.GetTemplate("ActivationEmail");
//currenttemplate.Body = String.Format(currenttemplate.Body,user1.MembershipUserId.ToString());
//PropertyMapper mapper = new PropertyMapper(user1);
//mapper.MapTemplate(currenttemplate);
//UpdateUI(currenttemplate);
currenttemplate.Body = currenttemplate.Body.Replace("Domain",System.Web.HttpContext.Current.Request.Url.ToString().Replace(System.Web.HttpContext.Current.Request.RawUrl.ToString(), ""));
currenttemplate.Body = currenttemplate.Body.Replace("MembershipUserId", user1.MembershipUserId.ToString());
msgMail.Subject = currenttemplate.Subject;
msgMail.Body = currenttemplate.Body;
// msgMail.Subject = "InvestorScopes Account Activation";
// //msgMail.BodyFormat = MailFormat.Html;
// string emailbody = "Thanks for registration in Investor scopes.To Activate your account click on the following link";
// msgMail.Body = emailbody;
//net mail
msgMail.IsBodyHtml = true;
msgMail.Priority = MailPriority.High;
SmtpClient sC = new SmtpClient("smtp.gmail.com");
//sC.Port = 25;
sC.Credentials = new NetworkCredential(Email, Pwd);
sC.EnableSsl = true;
//SmtpMail.Send(msgMail);
//net mail
sC.Send(msgMail);
emailid = Encryption.Encrypt(user1.UserName);
// msgMail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
Response.Redirect("ConfirmEmail.aspx?ID=" + username.ProviderUserKey + "&eid=" + emailid);
}
finally
{
objuserBAL = null;
}
// }
}
No comments:
Post a Comment