• Hosting Review
  • Hosting Comparison
  • Press Release
  • Hosting Tips
  • Hosting Review
  • Hosting Comparison
  • Press Release
  • Hosting Tips

Easy Ways to Add Meta Data to Your ASP.NET Pages

Jacques HuntHosting TipsNo comments

Meta descriptions and keywords help search engines figure out what your web pages are about. And while it is highly contended as to whether this does in fact help your website appear more often in search results, it’s better to just have your data as parser friendly as possible. This is just one of the things that Google and other search engines use in order to create your web pages search result descriptions. The little small snippet that appears under your sites link.

Then you need to give search engines all the help you can give. There’s a number of ways to set up your metadata in your ASP.NET pages. You can set them manually yourself in the <head> tag. The easiest way is of course to just add your tags directly to the page.

Old Fashion Way

<head>
     <meta name="description" content="some words here" />
     <meta name="keywords" content="word1, word2, word3" />
</head>

A few things to note when creating meta tags. Many search engines recommend not using the same text that you use in your title and also keeping the length at around 155 characters. It’s always best to follow the most used conventions. It’s something to note if your meta data is dynamically created.

Normally, 100% of all web pages aren’t static anymore, on average, and having the same meta keywords and descriptions on every page isn’t going to help your site win any usability awards any time soon. More often than not these will be set on the server side somewhere. Either stored in your database or calculated on the fly based on your pages content.

You can add as many different meta tags as you’d like in this method, and the content data can come from any source, such as a DB or calculated on the fly. Be aware though that there is nothing to stop this from adding multiple description or keywords. If you call SetupMeta() several times, then you’ll get several of the same tags in place.

Add It Literally

With the Literal control you can pretty much insert any text that you want into your webpage. You can declare the object on page_load and add it to the Header objects Controls collection.

protected void Page_Load(object sender, EventArgs e)
{
     Literal litMeta = new Literal();
     litMeta.Text = "<meta name="description" content="your meta description" />
     Headers.Controls.Add(litMeta);
}

You can also use the AddAt method to specify where on your Header you would prefer to add the control.

HtmlMeta Class

Even easier than the Literal control, you can also just make use of what .NET has to offer us and use the HtmlMeta class. The class gives you programmatic access to your pages meta tags.

protected void Page_Load(object sender, EventArgs e)
{
     HtmlMeta meta = new HtmlMeta();
     meta.name = "description";
     meta.content = "your content goes here";

     Header.Controls.Add(meta);
}

Adding the controls dynamically like above does lead to some issues though. If you happen to have any dynamic code blocks in your head section, say for example:

<head>
<script>
function func1()
{
       alert('<%=DateTime.Now%>');
}
</script>
</head>

Then we can’t dynamically modify the Header’s controls collection without getting the following run time error.

We also have to make sure that we don’t lose our data on post back. Not sure if search engines penalize for that scenario, but better safe than sorry. Because we’re adding the controls dynamically in the page load event of the full page life cycle, setting the controls only on IsPostback == false will not add the contents to viewstate, and as such we’ll lose our content on post back.

  • Tags:
  • asp net core
  • ,
  • asp net core tips
  • ,
  • asp net core tutorial
  • ,
  • asp net tips
  • ,
  • asp net tutorial
  • ,
  • metadata asp net core

Jacques Hunt

I'm an experienced marketing, SEO entusiast and technical writer since 2006. I had worked in many international high-tech companies. Now I'm focusing to write several blogs about web hosting to help people find suitable web hosting.
Related Articles
What is the Difference Between Blazor Server and Blazor Web Assembly
How to Add Attachments to Adobe Using C#
Why ASP.NET Website Eat High CPU Usage?

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

Our Sponsor
Best ASP.NET Hosting
Reliable ASP.NET Hosting

Cheap Shared Hosting

Categories
  • Hosting Comparison
  • Hosting Promotion
  • Hosting Review
  • Hosting Tips
  • Press Release
Recent Posts
  • What is the Difference Between Blazor Server and Blazor Web Assembly
  • Looking for HostGator ASP.NET Hosting Alternatives? Check it Out Here!
  • How to Add Attachments to Adobe Using C#
Hosting Partners
  • Cloud Hosting ASP.NET
  • Cheap Hosting ASP.NET
  • Windows Hosting Leader
  • Best Cloud Hosting ASP.NET
  • European Hosting ASP.NET
  • Hosting ASP.NET Review
  • Hosting Cheap ASP.NET
  • Hosting For E-Commerce
  • Best Windows Hosting ASP.NET
  • Discount Windows Hosting
  • UK Hosting ASP.NET
  • Hosting Partners
  • Cheap Hosting Windows
  • Reliable Hosting ASP.NET
  • Windows Hosting Bulletin
  • Windows Host ASP.NET
  • Review Hosting ASP.NET
  • Best Cheap Hosting ASP.NET
  • Hosting Review ASP.NET
  • Full Trust Hosting ASP.NET
  • Cheap OZ Hosting ASP.NET
  • Cheap ASP.NET Hosting Review
  • Hosting Partners
  • Best ASP.NET Hosting Review
  • Easy Hosting ASP.NET
  • Cheap Windows Hosting
  • Reliable ASP.NET Hosting
  • Windows Web Hosting Review
  • ASP.NET 5 Hosting
  • India Hosting ASP.NET
  • I Host Azure
  • Cheap Windows Hosting ASP.NET
  • Review Core ASP Hosting
  • FTC Disclosure

    TopReviewHostingASP.NET is an independent resource offering editorial and user web hosting reviews. We may receive monetary compensation from the companies whose services and products we review, though this has no impact on the quality of our reviews. The compensation does not influence our judgment in any way and does not result in higher or lower rankings for certain host companies. We promise that our reviews remain honest, unbiased and unprejudiced.

    Theme: Illdy.