This is an old blog. My new blog is moved here.

ASP.NET MVC SEO url regression for indexed ASPX pages

12/29/2009

My love affair with with the ASP.NET MVC framework is becoming a mature relationship now, so now the real challenge comes: how do I migrate all my old websites, on the ASP.NET MVC platform, without losing all my search engine indexed ASPX pages?

As challenging as it may sound, it is actually really simple:

In the Global.asax configure your default route as something like this:

	//old urls:
routes.MapRoute(
"Default", // Route name
"{url}", // URL with parameters
new { controller = "Home", action = "Index", url = "" } // Parameter defaults
);

Make sure you put this as the last route rule, because this rule catches everything that comes in the url.

Then in the home controller you can write something like this:

	public ActionResult Index(string url)
{

//page content
StringBuilder sb = new StringBuilder();

//pageTitle
string pageTitle = "";

switch (url)
{
case "blog.aspx":

//gets page specific query strings
string blogId = Request.QueryString["id"];

sb.Append("the blog id was: " + blogId);

break;
default:

pageTitle = "index";

sb.Append("helo index");

break;
}

//final build out
ViewData["page_title"] = pageTitle;
ViewData["page_content"] = sb.ToString();

return View();
}

There is little more work you need to do by converting all your code blocks into strings which in most of my apps I am doing anyway, so that I can use them on page as well as in AJAX responses.

Responses to The ASP.NET MVC SEO url regression for indexed ASPX pages

  1. sikat ang pinoy Says:
    Friday, February 05, 2010 1:47 AM
    for the latest blogengine 1.6 powered by asp.net now better for SEO. It increase website traffic and revenue SEO just got easy on aps.net.