Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Method not found: 'System.Web.UI.HtmlControls.HtmlGenericControl

$
0
0

On our website we are trying to dynamically create a number of <link> tags in our header (creating canonical tags). The original code used HTMLGenericControl to do this but it created a close </link> tag which is no good, I need it to create a self-closing tag (e.g. <link href="xxx" rel="canonical" />. In order to accomplish this I changed the code to use HtmlLink instead. Everything worked fine in our DEV and QA environment but when deployed into PROD we receive the "method not found: 'system.web.ui.htmlcontrols.htmlgenericcontrol' error.

Below is the method we are using.

using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI.HtmlControls;
using Nlc.Utilities;
using Sitecore.Data.Items;

/// <summary>
		/// Returns a link tag (as a HtmlGenericControl) with the specified params as attributes
		/// </summary>
		/// <param name="rel"></param>
		/// <param name="href"></param>
		/// <returns></returns>
		//public static HtmlGenericControl GetHtmlLinkTag(string href, string rel = null, string hreflang = null) {
        public static HtmlLink GetHtmlLinkTag(string href, string rel = null, string hreflang = null) {

			//var hgc = new HtmlGenericControl("link");
            var hgc = new HtmlLink();

            if (string.IsNullOrWhiteSpace(href)) return hgc;

			try
			{
                hgc.Attributes.Add("href", href);
				if (!string.IsNullOrWhiteSpace(rel)) hgc.Attributes.Add("rel", rel);
                if (!string.IsNullOrWhiteSpace(hreflang)) hgc.Attributes.Add("hreflang", hreflang);
			}
			catch
            {
				hgc.Dispose();
				throw;
			}

			return hgc;
		}

Our server is using the latest version of .NET framework.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>