Jul 28, 2021

2 min read

Set a Canonical URL for an HTML Document in .NET Core

When you have web pages that have variations of the same content, setting a canonical URL can be incredibly useful for instructing search engines on which pages are duplicates of each other. This is particularly true when you have a retail site that sells products that vary in size, color, etc. By utilizing the following API in .NET Core, you will be able to instantly set a canonical URL for an HTML document and avoid confusing and annoying the search engines with duplicate content.

To begin, we will install the package by running this command:

Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.2.1

With the installation out of the way, we are ready to configure the API key and call the function:

using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;
namespace Example
public class EditHtmlHtmlSetRelCanonicalExample
public void main()
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new EditHtmlApi();
var canonicalUrl = canonicalUrl_example; // string | The HTML canonical URL to set.
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Optional: Input file to perform the operation on. (optional)
var inputFileUrl = inputFileUrl_example; // string | Optional: URL of a file to operate on as input. (optional)
// Sets the rel canonical URL for the HTML document
byte[] result = apiInstance.EditHtmlHtmlSetRelCanonical(canonicalUrl, inputFile, inputFileUrl);
catch (Exception e)
Debug.Print("Exception when calling EditHtmlApi.EditHtmlHtmlSetRelCanonical: " + e.Message );

At the end of this quick operation, your canonical URL will be securely set — easy!