Dynamic Sitemap For AspDotNet MVC

What Is Sitemaps?

In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL so that search engines can more intelligently crawl the site.
Web crawlers usually discover pages from links within the site and from other sites. Sitemaps supplement this data to allow crawlers that support Sitemaps to pick up all URLs in the Sitemap and learn about those URLs using the associated metadata. Using the Sitemap protocol does not guarantee that web pages are included in search engines, but provides hints for web crawlers to do a better job of crawling your site. Sitemap including support from Google, Yahoo!, and Microsoft.
What Google Says About Sitemap?
 
“Using a sitemap doesnt guarantee that all the items in your sitemap will be crawled and indexed, as Google processes rely on complex algorithms to schedule crawling. However, in most cases, your site will benefit from having a sitemap, and you will never be penalized for having one.”

Sitemap XML Format
This document describes the XML schema for the Sitemap protocol. The Sitemap protocol format consists of XML tags. All data values in a Sitemap must be entity-escaped. The file itself must be UTF-8 encoded.

The Sitemap must:
•    Begin with an opening urlset tag and end with a closing urlset tag.
•    Specify the namespace (protocol standard) within the urlset tag.
•    Include a url entry for each URL, as a parent XML tag.
•    Include a loc child entry for each url parent tag.
All other tags are optional. Support for these optional tags may vary among search engines. Refer to each search engines documentation for details. Also, all URLs in a Sitemap must be from a single host, such as www.loopcoder.com or store.loopcoder.com.

Sample XML Sitemap
The following example shows a Sitemap that contains just one URL and uses all optional tags.
 


XML tag definitions

The available XML tags which are required are described below.
  • urlset    : Encapsulates the file and references the current protocol standard.
  • url        : Parent tag for each URL entry. The remaining tags are children of this tag.
  • loc       :URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters.
Dynamic Sitemap in ASP.NET MVC

Open New Empty MVC Project in Visual Studio. Here Visual Studio 2012 Showing. In solution panel we can see that default created directory of view, controller and model.




Take New Folder In View, rename it as Home and Take a view in Home. Set Name as your wish here I named it as Index.cshtml.




Now for viewing this page Create HomeController in your Controller return view from Controller  ActionResult for your created index.cshtml view. Now the main section for dynamic sitemap. First I create a model class “SitemapNode” that contains the necessary parameters for create an xml sitemap.




And finally process user request at “clsSitemap” class that I created in newly created BIZ directory.




Here user request first hit in “clsSitemap” class function SetSitemap which contains two parameter UrlHelper and Path. Urlhelper for generating desired url and path for saving finally created sitemap to domain root.



GetSitemapDocument” function creates xml format string from provided url list result that acquired from “GetNode” function.






From above picture i created three url for sitemap. You can create many more url by database system if your system has many url. Thats all. Run this project and see your sitemap just created in your domain or project building  root such as to view this browse your site by domain.com/sitemap.xml.

For clear concept you can also visit my youtube link

Dynamic Sitemap For ASP.NET MVC For Search Engine Indexing [English]

For Bangla


Leave a Reply

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