Skip to main content

Programmatically add the META tags to an ASP.NET page

Do you want to programmatically add the META tags to an ASP.NET page? You can try to the below code:

HtmlMeta metaDesc = new HtmlMeta();
metaDesc.Name = "description";
metaDesc.Content = "Your Description goes here";
Page.Header.Controls.Add(metaDesc);

HtmlMeta metaKey = new HtmlMeta();
metaKey.Name = "keywords";
metaKey.Content = "Your keywords here";
Page.Header.Controls.Add(metaKey);

Comments

Popular posts from this blog

Common Design Principles

There are number of common design principles that, like design patterns, best practice over the years to build maintainable software. I'm up to describe some widely used design principles though out the post. Following common principle are extracted by the same book that I mentioned before ( Professional ASP.Net Design Patterns - Scott Millet ). Principles are as follows: Keep It Simple Stupid (KISS) One common issue in software programming is over-complicating a solution. So main concern of this principle is keep the code simple but not simplistic. Eventually this will avoid unnecessary complexities. Don't Repeat yourself (DRY) Main concern of this principle is to avoid the repetition. In other words this is all about abstracting out the common functionalities into a single place. Ex: If there is a price calculation method in a system. It should lay in a single place there. Tell Don't Ask The Tell, Don’t Ask principle is closely aligned with encapsulation and the assignin...

How to configure SQL Server Session State with Custom Database

There are two steps got to follow to enable the SQL Server Session state to work 1. Configuring the database to support the SQL Server Session state. 2. Configuring your application to use SQL Server Session state. 1. Configuring the database to support the SQL Server Session state. .Net framework has a tool aspnet_regsql which you can use to add the table and stored procedure to support SQL Server Session state. You can find this tool in the following folder. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ aspnet_regsql.exe You can run this exe from window command prompt or you can directly run from SDK Command prompt. Executing the following command enables SQL Server Session state for a database server named local and store it in a custom database called CustomSessionDB. aspnet_regsql -C "Data Source=local;User Id=sa; Password=Sql2005" -ssadd -sstype c -d CustomSessionDB Executing this command creates a new database named CustomSessionDB that contains bot...

Adding a separator image to ASP.Net Menu Control

This what I did to add a separator to ASP.Net menu. I used Web.sitemap to bind the data to menu control. This how Web.sitemap looks like. <sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"> <sitemapnode> <sitemapnode url="~/Pages/DatingHome.aspx" title="Home" description="" separatorImageUrl="../../Images/but_blueSlice.jpg"> <sitemapnode url="~/Pages/Inbox.aspx" title="Inbox" description="" separatorImageUrl="../../Images/but_blueSlice.jpg"> </sitemapnode> </sitemapnode> This separatorImageUrl will tell you the image path of the separator. This event handler will do the rest of it. protected void Menu2_MenuItemDataBound(object sender, System.Web.UI.WebControls.MenuEventArgs e) { SiteMapNode smNode = (SiteMapNode)e.Item.DataItem; if (smNode["seperatorImageUrl"] != null) e.Item.SeparatorImageUrl = smNode[...