Hi Friends,
I'm a newbee and trying to set up a multi step registration for my website and using the CreateUserWizard Control which should generate an automatic Unique Key assigned to the new user. This Confirmation Code(GUID) is to be substituted into the email before the message is sent.
Problem:
The email is sent, however the confirmation code is not substituted in the email! in fact the email I get is in it's original HTML format. It's not in a normal email format.
here's what I have:

<asp:CreateUserWizard ID="CreateUserWizardControl" Runat="server" OnCreatedUser="CreateUserWizardControl_CreatedUser"

                        CreateUserButtonText="I Agree, Submit" TitleTextStyle-Height="50px" FinishDestinationPageUrl="~/Default.aspx"

                        ContinueDestinationPageUrl="~/ConfirmCode.aspx" ContinueButtonText="Continue to Homepage"

                        ContinueButtonType="Link" ActiveStepIndex="0" CssClass="register_text" 

                        OnCreateUserError="CreateUserWizardControl_CreateUserError" DisableCreatedUser="True" LoginCreatedUser="False" CompleteSuccessText=" For your security  a confirmation email containing your new password has been sent to your email address. Please check your email to activate your account."

                        OnSendingMail="CreateUserWizardControl_SendingMail">

                        <MailDefinition

                            From="info@company.com"

                            BodyFileName="CodeConfirmation.htm"

                            IsBodyHtml="true"

                            Subject="Registration Confirmation" />

CS File:

protected void CreateUserWizardControl_SendingMail(object sender, MailMessageEventArgs e)

    {

        MembershipUser User = Membership.GetUser(CreateUserWizardControl.UserName);

        string code = User.ProviderUserKey.ToString();



        MailAddress mTo = new MailAddress(e.Message.To.ToString());

        MailAddress mFrom = new MailAddress(e.Message.From.ToString());

        MailMessage m = new MailMessage(mFrom, mTo);

        m.Subject = e.Message.Subject;

        m.Body = e.Message.Body.Replace("<%ConfirmationCode%>", code);

        SmtpClient client = new SmtpClient();

        client.Credentials = new System.Net.NetworkCredential("info@company.com", "password}");

        client.EnableSsl = true;



        client.Send(m);

        e.Cancel = true;

    }

HTM file: CodeConfirmation.htm: (Below file appears in the email just the way you see it) there's no problem with UserName or any other substitution. the <%ConfirmationCode%> stays the same and no substitution takes place.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>Code Confirmation</title>

</head>

<body>

<%UserName %>,

Your Confirmation Code is <%ConfirmationCode %>

</body>

</html>

ConfirmCode.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Net.Mail;
using AspNet.StarterKits.Classifieds.BusinessLogicLayer;
using AspNet.StarterKits.Classifieds.Web;

public partial class ConfirmCode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        MembershipUser user = Membership.GetUser(txtUserName.Text);
        if (user == null)
        {
            lblError.Text = "Invalid User Name";
        }
        else
        {
            string providerCode = user.ProviderUserKey.ToString();
            string userCode = txtConfirmationCode.Text.Trim();
            if (providerCode != userCode)
            {
                lblError.Text = "Invalid Confirmation Code";
            }
            else
            {
                user.IsApproved = true;
                Membership.UpdateUser(user);
                Response.Redirect("~/SecretFiles/Secret.aspx");
            }
        }

    }
}

Please let me know where I'm going wrong?
Thank you

Problem solved.

Problem solved.

Hi,

I have the same problem, what did you have to do ?.

Kered

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.