This tutorial demonstrates how to add registration emails to verify new accounts with ASP.NET's CreateUserWizard Control using C#.
Modifying the CreateUserWizard Control
At this point in the tutorial I have created a new ASP.NET Web Site. What we need to do now is load up the Register.aspx page in the Account folder for editing in Design mode. We need to modify some properties within the CreateUserWizard Control named RegisterUser. To do this:
- Right click on the CreateUserWizard Control and select Properties.
- Set the DisableCreatedUser to 'True'
- Set the LoginCreatedUser to 'False'
Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.
Configuring SMTP SettingsWhat I have done for this is setup a new Gmail account which I will be configuring here, but it is important to understand that the SMTP settings will be different based on your email provider. I chose Gmail because their SMTP settings are readily available on the internet. As you go through this just use the correct setting for whatever email it is you are using.
To configure our SMTP Settings:
- Click the ASP.NET Configuration icon in the Solution Explorer to open up the ASP.NET Website Administration Tool.
- In the ASP.NET Website Administration Tool click the Application tab.
- Under the SMTP Settings header, click the Configure SMTP e-mail settings link.
- Under the Configure SMTP Settings header, configure the following properties.
- Server Name, the SMTP of your email provider, in my case smtp.gmail.com.
- Server Port, the Port of your email provider, in my case 587.
- From, the email you will be using, in my case PWRecoveryTutorial@gmail.com.
- Under Authentication, choose Basic
- Sender's user name, the username we use to login to the email we are using, in my case PWRecoveryTutorial@gmail.com.
- Sender's password, the password we use to login to the email account we are using here.
- Click Save.
- Close the ASP.NET Website Administration Tool.
<mailSettings> |
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
You will notice that the options we configured were added in here. For the email provider I am using, I am required to enable SSL (Secure Sockets Layer) for me to be able to actually send these emails out. To do this I am simply going to add enableSsl="true" in the network tag. So now my mail settings look like: <mailSettings> |
Note that yours will appear differently based on your email provider and that you don't have to enable SSL unless your email provider requires it.
Adding Code to the Register.aspx.cs Code Behind
Next, we need to add the code to actually create the email message and send it to the user when their account is created. Open up the Register.aspx.cs file for editing. At the top of this class we need to add two extra using statments:
using System.Net.Mail; |
Notice the RegisterUser_CreatedUser event method, this method executes when a new account is created. At the beginning of this event method we need to add the following code:
//Create a new user |
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
Create the VerifyNewUser.aspx PageNext, we need to add the VerifyNewUser page that we are linking our user to in the registration email. To do this:
- Add a new web form to the project named VerifyNewUser.aspx.
- Add a Label to the web form named Label1.
using System.Web.Security; |
Next, we are going to add the code that will approve the user's account in the Page_Load event method:
//if the id is in the query string |
No comments:
Post a Comment