Designing URLs in ASP.NET 4 Web Sites for Search Engine Optimization (SEO)

One of the best resources for learning how to increase traffic to your site is Rand Fishkin’s Among the many strategies Rand advocates is paying close attention to the structure and content of your URLs. The more search-engine-friendly and user-friendly a site’s URLs are, the more likely people are to find them and use them.

In a blog post on this subject, Rand provides 11 guidelines for optimizing URLs for user discovery, use, and re-use. Below is a summary:

  • Make the URL describe the content.
  • Keep it short.
  • Avoid query strings.
  • Descriptive words are better than numbers.
  • Include search keywords if possible.
  • Avoid subdomains (e.g.,
  • Minimize the number of folders.
  • Use hyphens instead of underscores.
  • Use consistent conventions throughout a site.
  • Do not use uppercase.
  • Avoid having multiple URLs generate the same content.

You can find some more information about URLs in a MarketPosition article.

In a typical ASP.NET Web site, your control over URL structure is limited. By default, URLs reflect your folder structure and file names. And if you want to pass information to a page by using variable data in the URL, you have to do it in a querystring.

If you are building a site from scratch, you might be able to create folder and file names that result in descriptive URLs with minimal folder depth, but that might also result in an awkward file and folder structure. If you want to improve SEO for an existing site, reworking your entire file and folder structure in order to make URLs more user-friendly can be impractical. And even if files and folder names are SEO-friendly, you are still stuck with querystrings whenever you want to include variable information in a URL.

Routing in ASP.NET helps resolve these dilemmas. Routing enables you to specify URL patterns that are independent of a site’s file and folder structure. It also enables you to pass variable information in segments of the URL instead of in querystrings.

For example, suppose that your folders organize pages by security access rules, and you have a ShowProductDetails.aspx page in a Customer folder because it is for customer use. The ShowProductDetails.aspx page takes a querystring parameter that provides the name of the product to display. Without routing, a URL to display widget details might look like the following:

By using ASP.NET routing, you can define a URL pattern like the following example which invokes ShowProductDetails.aspx but does not contain the folder name or the file name or a querystring:


With this route defined for your site, the following URL would display the same page as the one shown previously:

The only change required in ShowProductDetails.aspx is to retrieve the product name from the URL parameter productname instead of from the querystring parameter productname.

Routing was available in earlier versions of ASP.NET, but relatively complex code has been required to do basic tasks such as:

  • Configure a site for routing
  • Create routes
  • Access URL parameters in markup or code
  • Create URLs for hyperlinks by providing URL parameter values instead of hard-coding the URL itself (Hard-coding URLs would make it more difficult to change them as your needs change over time. For example, it is preferable to create hyperlinks to ShowProductDetails.aspx by specifying that productname=widget instead of by providing the actual productdetails/widget URL. ASP.NET can use the defined route pattern to create the correct URL format when the page is rendered. If later on you redefine the route pattern as itemdetails/{productname} , the hyperlink defined as productname=widget is automatically rendered with the new URL format itemdetails/widget.)

ASP.NET 4 includes several new features that simplify the code required to accomplish these tasks. For more information, see the following ASP.NET 4 Beta 1 documentation:

· ASP.NET Routing

· Walkthrough: Using ASP.NET Routing in a Web Forms Application

· How to: Define Routes for Web Forms Applications

· How to: Access URL Parameters in a Routed Page

· How to: Construct URLs from Routes

· System.Web.UI.WebControls.RouteParameter

-- Tom Dykstra
ASP.NET User Education
This posting is provided "AS IS" with no warranties, and confers no rights.

Give Your Feedback on the Documentation

Help us improve the developer documentation by taking the Visual Studio and .NET Framework Content Survey. This survey will give us a better understanding of the type of applications you are developing as well as how you use Help and how we can improve it. The survey takes only 10 minutes, and we appreciate your feedback