SEO Improvements in ASP.NET 4

Posted by Matthew Osborn on March 10, 2010

In ASP.NET 4 there are a few improvements that have been made to make it easier to make tweaks to improve Search Engine Optimization (SEO) on your pages. I’ll be the first to say it and definitely not the last but these improvements are not ground breaking or “sexy” but it does make your life a little easier. There are three main improvements that have been made. First is that webforms now has a better story for routing your pages to friendly URLs, however I am going to skip that one for now because that is a whole post itself. The other two are simply just properties that hang of the base page class that allow you to specify meta tags.

Meta tags are a special tag that can be placed in html to provide meta information about that particular page. This information can be anything from the author of the page to an expiration timeout for a caching system. (More information on common/standardized types of information can be found on the W3C site). For this post the ones that we are concerned with are the “Keywords” and “Description” content types. The keyword content type provides information to search engines about what information is on the page. However, for obvious reason most search engines don’t put to much “weight” on this meta tag. The description content type on the other hand is pretty useful, as most search engines include a short description of the site below the link to the site.

In this case most search engines will use the description meta tag as it likely provides more human friendly context to the site.

  1. <meta content="en-us" http-equiv="Content-Language" />
  2. <meta content="By trade I am a QA member on the Microsoft ASP.NET Team. By choice I host a podcast called Coding QA and work on LTAF." name="description" />

Okay so know you know what Meta tags are lets talk about how to get them to show up in your ASP.NET pages. There are two new properties that hang off of System.Web.UI.Page; MetaDescription and MetaKeywords. You can set these in the code behind of the page or in the page directive.

  1. <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
  2.     CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default"
  3.     MetaDescription="Description" MetaKeywords="Keywords" %>

Now I’m sure you can imagine a much more creative use for these than static text, like changing them based on the content of the page pulled from the database, but for now we will just use static text.

  1. <head>
  2.     <title>Home Page</title>
  3.     <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
  4.     <meta name="description" content="Description" />
  5.     <meta name="keywords" content="Keywords" />
  6. </head>

Well, that is all there really is to these two small improvements. Like I said there is nothing ground breaking or “sexy” about them. They were simply designed to help make your life a little more easy.