Click or drag to resize

ASP.NET web app development walkthrough

This article provides an example of implementing selected features in a custom ASP.NET web app via CodeTwo Exchange Rules SDK. The sample web app presented here allows to create a rule that adds a signature in Plain Text to messages sent by chosen users.

This article consists of the following sections:

Developing an ASP.NET web app
  1. Open Visual Studio and create a new ASP.NET Empty Web App project. In our case, we are going to call it: CodeTwoExchangeRulesProSdkWebApp.

    New Project
  2. Add references to assemblies from the SDK installation path. In Solution Explorer, right-click on References and click Add Reference.

    Add References

    Next, click Browse, locate the path to the previously downloaded CodeTwo Exchange Rules Pro SDK dll's, select them and click Add.

    Browse For Sdk Files

    In Reference Manager, confirm the added files via the OK button.

    Sdk Files Ready To Upload

    All files will be added to the project’s references.

    Refrence Added To Project
  3. Add a reference to the System.ServiceModel assembly.

    Add Reference To System.Service Model assembly

    Learn more about System.ServiceModel

  4. Now, as all the references have been added to the project, create a new Web Form that will be used to act as your web app’s interface.

    Create New Web Form
  5. Add system.serviceModel configuration to the Web.config file in your project. Next, within this file define the endpoint address (the web address of the Settings Storage WCF Service) that will enable connection of the web app to the Exchange Rules Service. The endpoint address should contain the name or the IP address of the server where your Exchange Rules Service resides (you can leave the default localhost if you develop the app directly on the server equipped with the Exchange Rules Service): http://your_host_name_or_IP_address_or_localhost:5020/ER.Engine/SettingsStorage/NoAuth. The configuration of the endpoint within the Web.config file can be done directly in the file's source (by modifying the address attribute of the endpoint element) or via the WCF Editor by right-clicking the Web.config file and choosing Edit WCF configuration.

    Code example:

    <?xml version="1.0"?>
          <compilation debug="true" targetFramework="4.5" />
          <httpRuntime targetFramework="4.5" />
            <binding name="SettingsStorageHttpEndpoint" />
            <binding name="MetadataExchangeHttpBinding_ISettingsStorage">
              <security mode="None" />
          <endpoint address="http://localhost:5020/ER.Engine/SettingsStorage/NoAuth"
              binding="basicHttpBinding" bindingConfiguration="SettingsStorageHttpEndpoint"
              contract="ER.SDK.ISettingsStorage" name="SettingsStorageHttpEndpoint" />
          <endpoint address="http://localhost:5020/ER.Engine/SettingsStorage/NoAuth/mex"
              binding="wsHttpBinding" bindingConfiguration="MetadataExchangeHttpBinding_ISettingsStorage"
              contract="ER.SDK.ISettingsStorage" name="MetadataExchangeHttpBinding_ISettingsStorage" />
    Wcf Editor
  6. Design a User Interface (UI) for the application. In this example, our app’s UI contains a rule-adding form that includes:

    • Rule's name

    • Sender's email address

    • Signature editor for a Plain Text template

    • Rule-adding button

    Code Example:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainForm.aspx.cs" Inherits="ExchangeRulesProSdkWebApp.MainForm" %>
    <!DOCTYPE html>
    <html xmlns="">
    <head runat="server">
        <style type="text/css">
            .auto-style2 {
                width: 150px;
            .auto-style3 {
        <form id="form1" runat="server">
            <table style="width:300px;">
                    <td class="auto-style3" colspan="2"><asp:Label ID="lblStatus" runat="server" ForeColor="#009900"></asp:Label></td>
                    <td class="auto-style3">
                        Rule's name
                    <td class="auto-style2">
            <asp:TextBox ID="txtRuleName" runat="server" Width="194px"></asp:TextBox>
                    <td class="auto-style3">
                        Sender's email address
                    <td class="auto-style2">
                         <asp:TextBox ID="txtSenderAddress" runat="server" Width="194px"></asp:TextBox>
                    <td class="auto-style3">Signature</td>
                    <td class="auto-style2">
            <asp:TextBox ID="txtSignature" runat="server" Height="100px" TextMode="MultiLine" Width="200px"></asp:TextBox>
                    <td class="auto-style3">&nbsp;</td>
                    <td class="auto-style2">
            <asp:Button ID="btnAdd" runat="server" OnClick="OnButtonAddClick" Text="Add rule" />
    Web AppsUI 2
  7. Next, add a click handler for the Add button in the MainForm.aspx.cs that will create and upload a new rule to the Settings Storage WCF Service.

    Code example:

    protected void OnButtonAddClick(object sender, EventArgs e)
        //Create a new instance of a client used to communicate with the SettingsStorage service
        var client = new ER.SDK.SettingsStorageClient("SettingsStorageHttpEndpoint");
        //Create a rule
        Settings.RuleDesc rule = new Settings.RuleDesc();
        //Assign the rule's name and enable it
        rule.Name = txtRuleName.Text;
        rule.Active = true;
        //Add an email address for a sender to whom the rule will be applied.
        if (!string.IsNullOrEmpty(txtSenderAddress.Text))
            //Create a filter collection for conditions.
            rule.Conditions = new ER.Shared.Settings.Filters.FilterCollection();
            //Add filter checking the SMTP email address of the sender.
            rule.Conditions.Add(new ER.Shared.Settings.Filters.FilterUserSmtpAddress(txtSenderAddress.Text, true, ER.Shared.Settings.Filters.EnumPersonType.Sender));
        //Create an Insert signature action
        Settings.Actions.ActionApplyInsertSignature actionInsertSignature = new Settings.Actions.ActionApplyInsertSignature();
        //Assign a signature template to the Plain Text content
        actionInsertSignature.CompositionLayout.PureText.Bottom.Content = txtSignature.Text;
        //Add the Insert signature action to the rule
        //Upload the created rule to SettingsStorage
        client.AddRule(null, rule);
        //Display info on the upload status via UI
        lblStatus.Text = "Rule has been added";
  8. Once all the steps above are executed, you should end up with the three major items configured:

    • The Web.config file with an endpoint defined.

    • MainForm.aspx.cs - this is the code behind the actions that will be performed via the created custom web app.

    • MainForm.aspx - the User Interface of your custom web app.

    Web App Created

Now your application is ready to be deployed to the production environment.

Deploying the ASP.NET web app to a production environment
  1. Build your project.

    Note Note

    Please note that you can modify the endpoint address in the Web.config file at any time if you need to connect to a different server equipped with the Exchange Rules Service than the server selected during initial development of your custom web app. Just open the Web.config file and enter a new address of the server with the Settings Storage WCF Service.

  2. Use Internet Information Services (IIS) Server Manager to check if .NET 4.0 is listed as supported framework within the Application Pools. If not, install ASP.NET 4.0. The easiest way to do that is to open the command prompt and run the following command:

    cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319

    Once this command is executed, type the following command:

    aspnet_regiis.exe -ir
    Add Net 40 Via Command Prompt

    .NET 4.0 will be added and listed within the Application Pools.

    IISApp Pools

    Learn more on how to specify a .NET Framework version for the Application Pools

  3. Create a folder for your custom web app using Windows Explorer: C:\inetpub\wwwroot\ER.WebClient.

    Catalog Created
  4. In IIS Manager, add a new application named ER.WebClient to Default Web Site, pointing its physical path to the folder: C:\inetpub\wwwroot\ER.WebClient.

    New App Added In Default Web Site

    Learn more on how to create a new web application

  5. Next, add the application to the Application Pools supporting .NET 4.0.

    Add Web Client To App Pool

    The application will be added to the Application Pools.

    Web Client Added To App Pools
  6. Copy the following items from the Output folder of your project to C:\InetPub\wwwRoot\ER.WebClient:

    • the bin folder

    • MainForm.aspx

    • Web.config

    • Web.Debug.config

    • Web.Release.config

    Output Folder
  7. Open any Internet browser and type in your application's address to launch the web app and start creating rules in CodeTwo Exchange Rules Pro that will add Plain Text signatures for selected users.

    Note Note

    To check the address of your application, access IIS Manager, right-click your application, choose choose Manage Application and click Browse.

    Custom Web App And Admins Panel

From now on each rule created in the web app will be instantly propagated to your Exchange Rules Service installations, processed by the Transport Agent, and applied to messages in your environment.

See next

Implementing features - this section contains articles on the features available in the provided API, with examples that may be used straight after download to create custom apps. You will also find information about setting various types of authentication (used when connecting an app to Exchange Rules Pro) and generating API Clients from the provided WSDL.