posted on Sunday, April 30, 2006 8:59 AM by Saravana

Customizing Membership Controls - Part I

Last one week, I was working in a little project were I used membership controls extensively. Main advantage of membership controls is productivity i.e. it reduces the development time a lot.

 

In addition to productivity advantage, these membership controls are fully customizable. This is also a main reason for these controls to be used in various applications.

 

In the project, I have customized the membership controls at many places. Therefore, I am planning to write a set of blogs to explain what are the customization options in membership controls I have used.

 

In this blog, I am going to talk about customization of e-mail content, which is sent from membership controls. The membership controls that sent email to the user are passwordrecovery control and createuserwizard control. I will talk about when e-mail is sent in createuserwizard control and how to enable this feature in my next blog.

 

Passwordrecovery control will send an email with new password when user request for password reset. By default, Passwordrecovery control sent an email with default content, which might not include your company name or your company website link.

 

Mostly you might want to customize the email sent to the customer. Passwordrecovery control provide an option for this through MailDefinition property, it has following properties

 

  1. BodyFileName – this property can be used to specify the text file path which contains the conent of the e-mail body.
  2. Subject – to specify the subject for the email
  3. From – this property is used to specify from address.
  4. CC – to specify Carbon Copy email.
  5. IsBodyHTML – to specify whether body is sent as html.
  6. Priority  – to set the priority of the mail.

 

Using these properties, you can customize email content. However, the next question, which comes to our mind, is how to add information about user in the mail. For example, you might want to add username and password detail in the mail.  By default membership control provides following placeholders,

 

1.      <% UserName %> - this placeholder will be replaced with username when the mail is sent to the user

2.      <% Password %> - this placeholder will be replaced with password when themail is sent to the user.

 

These placeholders can be used in the text file, which you are specifying in the BodyFileName property of the MailDefinition property.

 

Since only two placeholders are supported by membership controls, you might further want to customize this. For example, you might want to send email or security question  or your application specific user data along with username in the mail. In that case, you can use SendMail event of the membership control to customize further, for example to send email information in the mail. You can have <%Mail%> placeholder in your BodyFileName file, and in sendingmail event, you can replace this placeholder with the email of the user.

 

void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)

    {       

        MembershipUser user = Membership.GetUser(User.Identity.Name);

        e.Message.Body = e.Message.Body.Replace("<%Mail%>", user.Email);

    }

 

Note : Using membership API, you can get the email Id of the user.

Comments