How to Create A Meta tag using ASP.NET HtmlMeta Control Double Encodes Content

So I actually have one physical page/template in Umbraco that generates any number of web pages/URL’s dynamically from a database, and determined that I ought to produce bespoke content for the various SEO meta tags depending on the content of the page. 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 proper 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";

Which worked, solely I found this was being output to the browser:

Thunder & Lightning, " very, very, frightening"

ASP.NET looks 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 encryption, thus screw doing it properly. And now write the following code:

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.

Which Provider who can Give You The Best and Recommended Umbraco Hosting?

Happily, there are several reliable and recommended Web hosting out there that can help you get a handle on site speed and work to increase your Umbraco web rank. We are here to recommend you HostForLIFEASP.NET. HostForLIFEASP.NET is the most popular choice for people looking to host for the first time at an affordable price in Europe.

Their regular price starts at € 3.00/month only. Customers are allowed to decide on quarterly and annual plan supported their own desires. HostForLIFEASP.NET guarantees “No Hidden Fees” and industry leading ‘30 Days Cash Back’, folks might ask for a full refund if they cancel the service at intervals the first thirty days.

HostForLIFEASP.NET also give their customers an opportunity to create some cash by providing reseller hosting accounts. you’ll purchase their reseller hosting account, host unlimited websites thereon and even have the prospect to sell a number of your hosting area to others. This could be one amongst the best ways that of creating some cash on-line. You are doing not have to be compelled to worry concerning hosting stuff as they’ll beware of all the hosting desires of your shoppers.