The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
1. Open the code behind of CreateUserWizard control located under ~/Sitefinity/UserControls/Login folder
2. Subscribe for SendingMail event.
protected override void OnInit(EventArgs e) |
{ |
base.OnInit(e); |
this.CreateUserWizard1.CreatedUser += new EventHandler(CreateUserWizard1_CreatedUser); |
//SUBSCRIBE FOR SENDINGMAIL EVENT |
this.CreateUserWizard1.SendingMail += new MailMessageEventHandler(CreateUserWizard1_SendingMail); |
} |
3. Use MailMessageEventArgs to get/set the email subject and message.
void CreateUserWizard1_SendingMail(object sender, MailMessageEventArgs e) |
{ |
e.Message.IsBodyHtml = false; |
e.Message.Subject = Subject + Request.ServerVariables["SERVER_NAME"]; |
string subscriptionUrl = string.Concat(SubscriptionUrl, QueryString, CreateUserWizard1.UserName); |
e.Message.Body = MessageBody + subscriptionUrl; |
} |
4. You should implement custom public properties that will allow you to change the subject and body through the control designer instead of hardcoding them.
[System.ComponentModel.Category("Mail attributes")] |
public string Subject |
{ |
get |
{ |
if (string.IsNullOrEmpty(_subject)) |
return "You have requested subscription for:"; |
return _subject; |
} |
set { this._subject = value;} |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string QueryString |
{ |
get |
{ |
if (string.IsNullOrEmpty(_querystring)) |
return "?username="; |
return _querystring; |
} |
set { this._querystring = value; } |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string SubscriptionUrl |
{ |
get |
{ |
if (string.IsNullOrEmpty(_subscriptionUrl)) |
return "http://localhost:2889/EmptyProject/confirmsubscription.aspx"; |
return _subscriptionUrl; |
} |
set { this._subscriptionUrl = value; } |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string MessageBody |
{ |
get |
{ |
if (string.IsNullOrEmpty(_messageBody)) |
return "Please confirm your account using the link:"; |
return _messageBody; |
} |
set { this._messageBody = value; } |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string MailDefinitionFrom |
{ |
get |
{ |
string maildefinition = CreateUserWizard1.MailDefinition.From; |
if (string.IsNullOrEmpty(maildefinition)) |
return string.Empty; |
return CreateUserWizard1.MailDefinition.From; |
} |
set { CreateUserWizard1.MailDefinition.From = value; } |
} |
private string _subject; |
private string _querystring; |
private string _subscriptionUrl; |
private string _messageBody; |
Now I have to create a user control that will check whether the user is valid or not. If the user is valid i will approve the user using MembershipUser.IsApproved property. The user control is simple. In its template I added a Literal control that will be displayed only in case the user does not exist in the database.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EnableUser.ascx.cs" Inherits="CustomControls_EnableUser" %> |
<asp:Label ID="Label1" runat="server" /> |
In the code behind I added my logic that would check the query string and passed the value from the key.
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; |
public partial class CustomControls_EnableUser : System.Web.UI.UserControl |
{ |
protected void Page_Load(object sender, EventArgs e) |
{ |
Label1.Visible = false; |
// GET THE QUERY STRING KEYS |
string key = Request.QueryString.AllKeys[0]; |
string query = Request.QueryString[0]; |
if (key.Equals(Key) && !String.IsNullOrEmpty(query)) |
{ |
//GET THE USER FROM THE PROVIDER |
MembershipUser user = Membership.GetUser(query); |
if (user != null) |
{ |
user.IsApproved = true; |
Membership.UpdateUser(user); |
Response.Redirect("~/Sitefinity/Login.aspx"); |
} |
else |
{ |
Label1.Visible = true; |
Label1.Text = LabelText; |
} |
} |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string Key |
{ |
get |
{ |
if(string.IsNullOrEmpty(_key)) |
return "username"; |
return _key; |
} |
set |
{ |
this._key = value; |
} |
} |
[System.ComponentModel.Category("Mail attributes")] |
public string LabelText |
{ |
get |
{ |
if (string.IsNullOrEmpty(_labelText)) |
return "There is no such user registered"; |
return _labelText; |
} |
set |
{ |
this._labelText = value; |
} |
} |
private string _key; |
private string _labelText; |
} |
Note that the value of QueryString property of CreateUserWizard control should be the same as the value of Key property in EnableUser control.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.