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".
<!-- Web.Config Configuration File -->
<configuration> <system.web> <customErrors mode="Off"/> </system.web> </configuration> |
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.
<!-- Web.Config Configuration File -->
<configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> </system.web>
</configuration> |
while in fact, i do have
<customErrors mode="Off"/> in my web.config... Any ideas?