Email verification using the CreateUserWizard control

Last post 01-17-2008 11:14 AM by caligali. 6 replies.

Sort Posts:

  • Email verification using the CreateUserWizard control

    01-15-2008, 7:06 AM
    • Member
      72 point Member
    • caligali
    • Member since 12-31-2007, 6:14 PM
    • San Diego, CA
    • Posts 233

     

    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?
     


    --
    and learning..
  • Re: Email verification using the CreateUserWizard control

    01-15-2008, 8:11 AM
    • Star
      8,062 point Star
    • Careed
    • Member since 06-24-2002, 7:37 AM
    • Lubbock, TX
    • Posts 1,572
    Does mail.ask.com require SSL?  If so, then set mailClient.EnableSsl = true.
    Christopher Reed
    "The oxen are slow, but the earth is patient."
  • Re: Email verification using the CreateUserWizard control

    01-15-2008, 8:14 AM
    • Member
      72 point Member
    • caligali
    • Member since 12-31-2007, 6:14 PM
    • San Diego, CA
    • Posts 233

     nope.

    --
    and learning..
  • Re: Email verification using the CreateUserWizard control

    01-15-2008, 8:32 AM
    • Star
      8,062 point Star
    • Careed
    • Member since 06-24-2002, 7:37 AM
    • Lubbock, TX
    • Posts 1,572

    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
    "The oxen are slow, but the earth is patient."
  • Re: Email verification using the CreateUserWizard control

    01-15-2008, 8:44 AM
    • Member
      72 point Member
    • caligali
    • Member since 12-31-2007, 6:14 PM
    • San Diego, CA
    • Posts 233

    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..
  • Re: Email verification using the CreateUserWizard control

    01-17-2008, 5:53 AM
    Answer

    caligali:

         protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            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>.";        
        }

     

    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);

    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.

    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.
  • Re: Email verification using the CreateUserWizard control

    01-17-2008, 11:14 AM
    Answer
    • Member
      72 point Member
    • caligali
    • Member since 12-31-2007, 6:14 PM
    • San Diego, CA
    • Posts 233

    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..
Page 1 of 1 (7 items)