Search code examples
c#asp.netwebformsasp.net-membershippassword-recovery

ASP.NET Membership Password Recovery E-mail Customize


I have an email template (aspx page) for password recovery.

I call it onSendingMail like this:

StringWriter _writer = new StringWriter();
HttpContext.Current.Server.Execute("emailPasswordRecovery.aspx", _writer);
string body = _writer.ToString();
e.Message.IsBodyHtml = true;
e.Message.Subject = "New Password";
e.Message.Body = body;

But when I added <%Password %> to get the password in the HTML line, I got the error:

The name 'Password' does not exist in the current context

What is wrong?


Solution

  • I solved my problem:

    • Removed onSendingMail events.
    • Created a new HTML web page and used <%Password%> to get password where I want. (Also you can get <%UserName%>.)
    • Set mailBodyDefinition from properties window
    • isBodyHTML = true
    • And done.