ASP.NET Tutorial – 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:

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:

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

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:

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.

No #1 Recommended ASP.NET Core Hosting

ASPHostPortal.com

ASPHostPortal.com  is the leading provider of Windows hosting and affordable ASP.NET MVC Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.

HostForLIFE.eu

HostForLIFE.eu guarantees 99.9% uptime for their professional ASP.NET MVC hosting and actually implements the guarantee in practice. HostForLIFE.eu is the service are excellent and the features of the web hosting plan are even greater than many hosting. HostForLIFE.eu offer IT professionals more advanced features and the latest technology. Relibility, Stability and Performance of  servers remain and TOP priority. Even basic service plans are equipped with standard service level agreements for 99.99% uptime. Advanced options raise the bar to 99.99%. HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools.

DiscountService.com.au

DiscountService.com.au is The Best and Cheap ASP.NET MVC Hosting. DiscountService.com.au was established to cater to an under served market in the hosting industry web hosting for customers who want excellent service. DiscountService.com.au guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability. DiscountService.com.au has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. DiscountService.com.au is devoted to offering the best Windows hosting solution for you.