Programmatically Setting <meta> Keywords and Description Tags
- The <head> element in an HTML document provides metadata about the web page, including the page's title (via the <title> element), and links to external CSS and JavaScript files, among other information.
- ASP.NET offers ways to have this metadata assigned automatically or programmatically. For example, you can programmatically set the page's title using the Page class's Title property. (See Dynamically Setting the Page's Title for more information.) Likewise, when using ASP.NET Themes any stylesheets defined in the theme are automatically included in the page's <head> section.
- When crawling through the pages in a website, a search engine spider will examine the <head> section to determine more information about the page. A page's keywords and a human-friendly description of the page may be included in the <head> section through the use of <meta> elements. For example, the following <head> element includes a hard-coded title and hard-coded keyword and description <meta> tags:
<head runat="server">
<title>The web page title...</title>
<meta name="keywords" Content="your,keywords,each
one delimited by a,comma" />
<meta name="description" content="A description of your web page
goes here." />
</head>
- ASP.NET 4 adds two new properties to the Page class that allow for these two <meta> tags to be specified programmatically:
* MetaKeywords, and
* MetaDescription
- You can set these properties from code just like you can the Page.Title property. For example, to generate the above></meta> tags programmatically we'd simply need to add the following lines of code to the ASP.NET page's code-behind class:
Page.MetaKeywords = "your,keywords,each one delimited by a,comma";
Page.MetaDescription = "A description of your web page goes here.";



0 comments:
Post a Comment