Meta tags in HTML allows the website to be more discoverable by the search engines. The meta tag also allows the search engines to index the website according to the Keywords and Description. In this article we are going to examine the advancements in setting the meta tags using ASP.NET 4.0.

Setting Meta Tags Manually:

The easiest way to set the meta tags is to manually declare them in the master page. This can be performed in the HTML view.



The above works without any problem but the main setback is that we cannot change the Keywords or the Description dynamically. In the next section we are going to demonstrate how to change the meta tags dynamically in ASP.NET 2.0 framework.

Changing Meta Tags Dynamically Using ASP.NET 2.0:

If you are still working in .NET 2.0 then don't worry you can still change the meta tags dynamically. The HtmlMeta class allows you to add meta content to your page.

  

If you run the page you will notice that the meta tag with "Keywords" name has been added to the page.

Changing Meta Tags Dynamically Using ASP.NET 4.0:

In ASP.NET 4.0 we can easily set the meta tags dynamically using the properties exposed in the Page class. The implementation is shown below:

  

Conclusion:

In this article we learned how to dynamically add the meta tags to ASP.NET application. We also learned how ASP.NET 4.0 framework allows us to accomplish this task easily.