Posted in:

How to Dynamically Generate Sitemaps for Your ASP.NET Site

There are many tips to improve your ASP.NET site’s SEO but one of those, the importance of which is often underestimated is sitemaps. Sitemaps offer a way of informing Google and other search engines about the web pages on your ASP.NET site that are available for crawling therefore improving the site’s search rankings. In this post, we are going to give a guide on dynamically generating sitemaps for your ASP.NET site.

Why Use Sitemaps?

Before diving into the main body, let’s take a few minutes to have a brief look at sitemaps and its benefits.

Sitemap, just as the name implies, refers to a map of your ASP.NET site, including the structure of the site, the sections, as well as the links between them. On the one hand, sitemaps makes it easier to navigate your ASP.NET site. On the other hand, having an updated sitemap on your ASP.NET site listing your site’s URLs and additional metadata about each makes search engines like Google, Yahoo, or Bing more intelligently crawl the site.

Besides easier navigation and better visibility by search engines, sitemaps offer you a chance to rely less on external links for bringing search engines to your ASP.NET site as long as it is created and submitted to the search engines. Meanwhile, sitemaps can be helpful even for broken internal links, orphaned pages and other kind of messy internal links which are impossible to be reached in other ways, though undoubtedly the best way is to fix them rather than leaning on sitemaps.

HTML Sitemap and XML Sitemap

Generally speaking, sitemap comes in two different types: HTML sitemaps and XML sitemaps. A HTML sitemap is a page within your ASP.NET site that links to all the other important pages on the site, while an XML sitemap does pretty much the same thing but being only visible and useful to search spiders instead of human visitors. So, here’s the question: should you use an HTML sitemap or a XML sitemap?

The question is asked a lot but usually the correct answer should be both. Using XML sitemaps can help search engines to see what pages you have on your ASP.NET site, including all the internal pages. As well, if you have a great number of posts or pages that are unnecessary to link to from the homepage, using XML sitemaps can help connect your web pages more efficiently. Similarly, having HTML sitemaps makes it possible for people who are not familiar with your ASP.NET site and the information you have on it to click on what they want, and get taken to that location with ease.

To conclude: a HTML sitemap gives your ASP.NET site visitors a comprehensive understanding of your site, while a XML sitemap more specifically caters to the search engines, both of which are vital to your success.

Dynamically Generate a Sitemap for Your ASP.NET Site

First, start with a SitemapNode which represents a web page in a sitemap structure:

16-1

After that, you need to create a collection of SitemapNode’s. In below example, we add a collection of product pages after adding Home, About, and Contact three main pages of an ASP.NET site. You need to get every product ID from your database so that you can use which to generate a product URL as required. For generating absolute URLs but relative ones, you can make use of an extension method called AbsoluteRouteUrl:

16-2

The next step is turning the collection of SitemapNode’s into XML:

16-3

Now, adding an action method to your HomeController for getting to the XML sitemap on your ASP.NET site. And you can place your sitemaps at the root of your ASP.NET site at sitemap.xml through creating a route with a file extension using the following line in your Web.config file:

16-4

16-5

Notes on Implementing Sitemaps on Your ASP.NET Site

  1. Add the “sitemap:” directive to your Robots.txt file: “Sitemap: <fully qualified path to your sitemap file, or sitemap index file>”
  2. Give the highest priority to products pages, newsletter signup pages, and other pages that generate the most value from your customers as well as those you clearly know that your customers will be most interested in.
  3. Avoid giving all web pages of your ASP.NET site 1.0 priority;
  4. Don’t expect that you can see an impact right away from implementing sitemaps because search engines need time to optimize the implementations and figure out how to use such information exactly.

Conclusion

Adding a dynamic sitemap to your ASP.NET is a recommended way to improve your site’s search rankings as it makes your web pages easily be crawled. The way of dynamically generating a sitemap is also simple that every person can quickly grasp. However, besides using sitemaps, hosting your ASP.NET site with a best SEO Windows web hosting like HostGator, GoDaddy, or IXWebHosting could be a more effective solution to improve SEO rankings of your site.

Leave a Reply

Your email address will not be published. Required fields are marked *