I had a field in my database with the SEO tags already html encoded - with content like:
Thunder & Lightning, "very, very, frightening"
Reading up, the correct way to add a meta tag to the page <head> in c# (and therefore Razor in Umbraco) goes a little bit like this:
Page page = HttpContext.Current.Handler as Page;
HtmlMeta metaDescription = new HtmlMeta();
metaDescription.Name = "description";
metaDescription.Content = "My description content";
page.Header.Controls.Add(metaDescription);
Which worked, only I found this was being output to the browser:
Thunder &amp; Lightning, &quot; very, very, frightening&quot;
ASP.NET seems to be HTML encoding a string that's already HTML encoded, leading to the above mess.
Couldn't find an obvious way to stop the above code from carrying out the unnecessary HTML encoding, so screw doing it properly. Here is my working solution:
Page page = HttpContext.Current.Handler as Page;
LiteralControl litMetaDescription = new LiteralControl();
litMetaDescription.Text = "<meta name=\"description\" content=\"Description\"/>");
page.Header.Controls.Add(litMetaDescription);
Providing you are sure that the string you are passing is properly HTML encoded, the above will work fine.
Best Umbraco 7.4.1 Hosting Recommendation
One of the most important things when choosing a good Umbraco
7.4.1 hosting is the feature and reliability. HostForLIFE
is the leading provider of Windows hosting and affordable Umbraco
7.4.1, their
servers are optimized for PHP web applications such as the latest Umbraco version. The performance and the uptime of the hosting service are excellent
and the features of the web hosting plan are even greater than what many
hosting providers ask you to pay for.
At HostForLIFE.eu, customers can also experience fast Umbraco
hosting. The company invested a lot of money to ensure the best and fastest
performance of the datacenters, servers, network and other facilities. Its
datacenters are equipped with the top equipments like cooling system, fire
detection, high speed Internet connection, and so on. That is why
HostForLIFE.eu guarantees 99.9% uptime for Umbraco. And the engineers do
regular maintenance and monitoring works to assure its Umbraco hosting are
security and always up.
0 comments:
Post a Comment