mostlylucid

STATIC ARCHIVE of mostlylucid.co.uk of old
posts - 916, comments - 758, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

ASP.NET 4.0: Page.MetaKeywords and Page.MetaDescription simple, but useful!

One of the smaller additions we've made to ASP.NET 4.0 WebForms is the addition of two properties on the Page class, Page.MetaKeywords and Page.MetaDescription.
What these two properties do is provide access to / create meta tags within your  page as follows:

<head runat="server">

    <title>Untitled Page</title>

    <meta name="keywords" content="These, are, my, keywords' />

    <meta name="description" content="This is the description of my page" />

</head>

Simple, right? In fact these two properties work the same way as Page.Title works:

1. If there are no meta tags in the head element matching the property names e.g., name="keywords" for Page.MetaKeywords and name="description" for Page.MetaDescription then we create these tags and fill in the string you entered as the content.
2. If there are already meta tags with these names we provide get / set access to the existing tags...

Of course you can set these in code, so the content could come from a DB to describe what you particular page is for etc...

Oh, and you can also set these in the Page tag at the top of your WebForm as follows:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" Metaeywords="Hello" MetaDescription="This is my description" %>

This will override the meta tag contents (if any) already declared in the page.

Note, that the description in these tags is only really used for improving your snippets on Google, Google and Live don't use the Keywords for anything but other search engines may.

A simple feature but it is pretty useful (and saves you messing about with adding these manually / writing your own code to create these.

Print | posted on Thursday, January 29, 2009 7:49 AM | Filed Under [ ASP.NET 4.0 ]

Feedback

# re: ASP.NET 4.0: Page.Keywords and Page.Description simple, but useful!

Great to know! I take care of these myself in just about every project. They are finally part of a page.

1/30/2009 9:51 AM | Ray Fan

# re: ASP.NET 4.0: Page.Keywords and Page.Description simple, but useful!

Good article. More articles for ASP.NET 4.0 are waited for.

2/9/2009 11:53 PM | Spencer

# re: ASP.NET 4.0: Page.Keywords and Page.Description simple, but useful!

Well thats one way- If you use a sitemap file/provider these should really be placed in there as they are page specific. For the last few years I have ghad to wire up alll of this with custom attributes on my site map files/providers to output the description, title and keywords.

Any danger of this becoming standardised into the Site Map architecture?

Ben

2/11/2009 8:52 AM | Ben

# re: ASP.NET 4.0: Page.Keywords and Page.Description simple, but useful!

I tried this properties on VS 2010(an .NET 4.0 web site) but I couldn't use Keyword property. While I typed Keywords in Page directive or Page.Keywords in code-behind, both of them caused error. Why?

2/13/2009 12:00 AM | Ugur

Gravatar

# re: ASP.NET 4.0: Page.Keywords and Page.Description simple, but useful!

Hi Ugur, yeah I should have added a caveat to all of my ASP.NET 4.0 blog posts. The CTP you currently have access to really has nothing (well, apart from a very early version of ClientID) included. You will first see these features in Beta 1...

2/14/2009 1:50 PM | scott

Gravatar

# re: ASP.NET 4.0: Page.MetaKeywords and Page.MetaDescription simple, but useful!

ASP.NET has gone in unmanaged and unstable state where we have 100s of project coded in ASP.NET 2.0 and when we open them in 2008 nothing opens, upgrading to 3.5 are mere
nightmares. And finally so many new technologies just to boost the marketing headlines. But come on guys, its easy for one blogger to just blog about able to mix technologies with writing 100s of lines of code which one geek can understand. Have you even worked on any project involving more then 5 developers? Practically we are spending more monty to train new things to our staff, more money to buy new tools, more money to manage projects and more and more money to sit and search world of forums to find why one thing doesnt work then actually doing simple development.

6/26/2009 11:07 PM | play HORSE Poker

Comments have been closed on this topic.

Powered by: