Ive been doing some reading on this topic, http://forums.asp.net/p/1029088/1408275.aspx, and http://www.aspcode.net/Requiring-email-verification-for-new-accounts.aspx, but I cant seem to figure out how to send emails to verify email accounts when creating
a new account.
My code looks like:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
//Send email to user for verifying account
CreateUserWizard cuw = (CreateUserWizard)sender;
MembershipUser user = Membership.GetUser(cuw.UserName);
Guid userId = (Guid)user.ProviderUserKey;
System.Net.Mail.MailMessage EmailMsg = new System.Net.Mail.MailMessage("info@ask.com", CreateUserWizard1.Email);
EmailMsg.Subject = "Email Verification from ask.com";
EmailMsg.IsBodyHtml = true;
EmailMsg.Body = "Thanks for registering with www.ask.com!<br /><br />Your activation link : <a href=http://www.ask.com/activate.aspx?ID=" + userId.ToString() + ">Link</a>.";
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
//This object stores the authentication values
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("smtpserverinfo", "smtpserverpassword");
the problem is that when I click on the link it generates with the user id in the URL, it throws this error:
Server Error in '/' Application.
Runtime Error
Description:
An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local
server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors>
tag should then have its "mode" attribute set to "Off".
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
Then try tweaking your web.config file. I have run into this issue several times and sometimes I toggle the customErrors value a couple of times between RemoteOnly and Off and it tends to start working. Otherwise, verify that this is set as an application
in IIS and then you don't have any other web.config files that might be conflicting with it.
Have you successfully sent an email through mail.ask.com prior to this?
Christopher Reed, MCT, MCPD
"The oxen are slow, but the earth is patient."
the email's job is to create the link to the activation page and send it, right?
now, assuming that was successful, which i cannot test until i upload to server and thats another issue... but, my problem is that, even when I generate the link myself, and enter it in the URL, it fails. am i misunderstanding how this works? cause im thinking
that the first part only generates a URL, and once that URL is clicked, then the activation should occur, no?
So you need to retrieve the userid from queryString like Request.QueryString["ID"], right?
It seems that you are looking for user with empty guid.
Best Regards
XiaoYong Dai
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
My email creates a link to the page: http://www.myApplication.com/activate.aspx?ID=21c46d2d-76cf-446b-847c-efe0758f4975
But, since Im running the code on my localhost, www.myApplication wont do me any good. I had to change it to http://localhost:56300/myApplication/activate.aspx?ID=21c46d2d-76cf-446b-847c-efe0758f4975 so at least now it tries to run the code in activate.aspx
Then, in activate.aspx, like XiaoYong Dai said, I had to pass the query string to the Guid: Guid oGuid = new Guid(Request.QueryString["ID"]);
and that did it. Thanks a lot!
caligali
Member
83 Points
268 Posts
Email verification using the CreateUserWizard control
Jan 15, 2008 11:06 AM|LINK
Ive been doing some reading on this topic, http://forums.asp.net/p/1029088/1408275.aspx, and http://www.aspcode.net/Requiring-email-verification-for-new-accounts.aspx, but I cant seem to figure out how to send emails to verify email accounts when creating a new account.
My code looks like:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
//Send email to user for verifying account
CreateUserWizard cuw = (CreateUserWizard)sender;
MembershipUser user = Membership.GetUser(cuw.UserName);
Guid userId = (Guid)user.ProviderUserKey;
System.Net.Mail.MailMessage EmailMsg = new System.Net.Mail.MailMessage("info@ask.com", CreateUserWizard1.Email);
EmailMsg.Subject = "Email Verification from ask.com";
EmailMsg.IsBodyHtml = true;
EmailMsg.Body = "Thanks for registering with www.ask.com!<br /><br />Your activation link : <a href=http://www.ask.com/activate.aspx?ID=" + userId.ToString() + ">Link</a>.";
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
//This object stores the authentication values
System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("smtpserverinfo", "smtpserverpassword");
mailClient.Host = "mail.ask.com";
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = basicAuthenticationInfo;
mailClient.Send(EmailMsg);
}
and in activate.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Guid oGuid = new Guid();
MembershipUser oUser = Membership.GetUser(oGuid);
if (oUser != null && oUser.IsApproved == false)
{
oUser.IsApproved = true;
Membership.UpdateUser(oUser);
System.Web.Security.FormsAuthentication.RedirectFromLoginPage(oUser.UserName, false);
}
}
the problem is that when I click on the link it generates with the user id in the URL, it throws this error:
Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<customErrors mode="Off"/> in my web.config... Any ideas?
and learning..
Careed
All-Star
16664 Points
3233 Posts
Re: Email verification using the CreateUserWizard control
Jan 15, 2008 12:11 PM|LINK
"The oxen are slow, but the earth is patient."
caligali
Member
83 Points
268 Posts
Re: Email verification using the CreateUserWizard control
Jan 15, 2008 12:14 PM|LINK
nope.
and learning..
Careed
All-Star
16664 Points
3233 Posts
Re: Email verification using the CreateUserWizard control
Jan 15, 2008 12:32 PM|LINK
Then try tweaking your web.config file. I have run into this issue several times and sometimes I toggle the customErrors value a couple of times between RemoteOnly and Off and it tends to start working. Otherwise, verify that this is set as an application in IIS and then you don't have any other web.config files that might be conflicting with it.
Have you successfully sent an email through mail.ask.com prior to this?
"The oxen are slow, but the earth is patient."
caligali
Member
83 Points
268 Posts
Re: Email verification using the CreateUserWizard control
Jan 15, 2008 12:44 PM|LINK
the email's job is to create the link to the activation page and send it, right?
now, assuming that was successful, which i cannot test until i upload to server and thats another issue... but, my problem is that, even when I generate the link myself, and enter it in the URL, it fails. am i misunderstanding how this works? cause im thinking that the first part only generates a URL, and once that URL is clicked, then the activation should occur, no?
and learning..
XiaoYong Dai...
All-Star
38312 Points
4229 Posts
Re: Email verification using the CreateUserWizard control
Jan 17, 2008 09:53 AM|LINK
Hi
Base on my understanding, you want to approve user in activate.aspx, I suppose it's http://www.ask.com/activate.aspx?ID=1234567
So you need to retrieve the userid from queryString like Request.QueryString["ID"], right?
It seems that you are looking for user with empty guid.
XiaoYong Dai
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
caligali
Member
83 Points
268 Posts
Re: Email verification using the CreateUserWizard control
Jan 17, 2008 03:14 PM|LINK
I had a few errors.
My email creates a link to the page: http://www.myApplication.com/activate.aspx?ID=21c46d2d-76cf-446b-847c-efe0758f4975
But, since Im running the code on my localhost, www.myApplication wont do me any good. I had to change it to http://localhost:56300/myApplication/activate.aspx?ID=21c46d2d-76cf-446b-847c-efe0758f4975 so at least now it tries to run the code in activate.aspx
Then, in activate.aspx, like XiaoYong Dai said, I had to pass the query string to the Guid: Guid oGuid = new Guid(Request.QueryString["ID"]);
and that did it. Thanks a lot!
and learning..