Skip to content

adtoniq/adtoniq-for-dot-net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

adtoniq-for-dot-net

Adtoniq for .NET servers

This is part of a Visual Studio project to build a web server demonstrating how to integrate Adtoniq with your .NET based web server. You can find a running example of this code at https://adtoniq-for-dot-net20191022071117.azurewebsites.net/ .

Adtoniq for .NET implements the server-to-server communications required between your webserver and Adtoniq. When your server starts up, Adtoniq will request JavaScript from Adtoniq servers. Subsequently, once a day Adtoniq will initiate communications with your webserver, using a secure protocol, to transmit the latest JavaScript required to ensure Adtoniq continues functioning as new ad block rules are added, or ad blockers are enhanced with new capabilities. In addition, once you are live with Adtoniq, Adtoniq will monitor your website to determine if ad blockers are adding new filter list rules specifically to block ads on your website, and if they are, Adtoniq will immediately send your site an update to ensure your advertising is not blocked. These updates sent by Adtoniq are cached between updates from Adtoniq - you can read more about caching below.

By default, Adtoniq's servers will communicate with your website using the root of your website over https, for example https://www.mysite.com/. You can customize this URL to be any URL you like, for example https://www.mysite.com/adtoniq. To customize your update URL, contact adtoniq at support@adtoniq.com and request a custom update URL.

Caching and CDNs

The JavaScript is stored in a static global, so that it can quickly be injected into the <head> section of your site. If you cache your HTML, for example in a CDN, you'll need to ensure that your cache is eventually updated. Some caches are updated automatically whenever page content changes, while other caches must be updated manually. You can implement the updatePageCache() function shown in Adtoniq.cs to add code to manually update your cache.

In most cases, the previous version of JavaScript will continue to function for however long it takes to update your cache / CDN, even if that takes many hours.

How to integrate this with your .NET web server

This example was generated by Visual Studio as a sample application for .NET Web Forms. It was then modified to add Adtoniq services.

First, you must obtain your Adtoniq API key. Contact Adtoniq to obtain your API key. Then edit the class AdtoniqLauncher.cs and enter the API key you obtain from Adtoniq, replacing the text that reads "put-your-api-key-here".

To activate Adtoniq on all pages of your site, modify the Site.Master file by adding the following line in the <head> section of the page:

<% Response.Write(AdtoniqForDotNet.AdtoniqLauncher.adtoniq.JavaScript); %>

This will inject the scripts and styles necessary for Adtoniq to function.

Modify the SiteMaster.cs file to add the following code snippet inside your Page_Load() function:

if (!this.IsPostBack)
{
    string nonce = Request.Params.Get("adtoniqNonce");
    string apikey = Request.Params.Get("adtoniqAPIKey");

    if (! string.IsNullOrEmpty(nonce) && ! string.IsNullOrEmpty(apikey) && apikey.Equals(AdtoniqLauncher.apiKey))
    {
        AdtoniqLauncher.adtoniq.getLatestJavaScript(nonce);
    }
}

The above code will look for secure updates coming from Adtoniq.

The Adtoniq.cs file implements the server-to-server communications required with Adtoniq.

That's it! Contact support@adtoniq.com with any questions.