title: Creating canonical URL dynamically using JavaScript
body: <p>I have two domains www.example.com and www.example.net pointing to the same website. www.example.com is my primary domain (main domain). I want to set the canonical URL on all pages such that whenever user / bot is seeing the pages on www.example.net, the canonical element is rendered and points to pages on www.example.com. </p>
  
  <p>Example: If a user is viewing the page www.example.net/pagename the canonical element should be rendered pointing to www.example.com/pagename</p>
  
  <pre><code>&lt;link href="https://www.example.com/pagename" rel="canonical"&gt;
  </code></pre>
  
  <p>So, the pagename will be dynamic and will change for each page. </p>
  
  <p>Can this be achieved using JavaScript? If not, can we do the same using C# as the site is built on Asp.Net MVC / Umbraco.</p>
  
  <p>Thanks</p>