Wiki

Clone wiki

EasySiteMap / Home

Welcome

Function of EasySiteMap

Generate the sitemap.xml and sitemap_index.xml files easily and quickly.

Instalation

Available installation on Nuget: EasySiteMap

PM> Install-Package EasySiteMap 

Full Documentation Here

Basic Example (Only one sitemap.xml)

#!c#

using EasySiteMap;
using EasySiteMap.Extensions;

...

UrlHelper urlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);

List<SiteMapItem> lst = new List<SiteMapItem>();
lst.Add(new SiteMapItem(urlHelper.QualifiedAction("Index", "Home")));
lst.Add(new SiteMapItem(urlHelper.QualifiedAction("About", "Home")));
lst.Add(new SiteMapItem(urlHelper.QualifiedAction("Contact", "Home")));

SiteMapItem itemmap = new SiteMapItem("http://localhost/yourote/100", DateTime.Now, ChangeFrequency.Always, 0.5);
lst.Add(itemmap);

EasySiteMapGenerator g = new EasySiteMapGenerator(new SiteMapConfig()
{
    Domain = @"localhost.com/",
    LocalFile = Server.MapPath("~"), //For development use [C:\your_pagetest]
    TotalItensByFile = 50000
});

g.GenerateSiteMap(lst);

This code will generate the sitemap.xml file in the root of your site.

#!XML

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

<urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://localhost:55425/</loc>
   </url>
   <url>
      <loc>http://localhost:55425/home/about</loc>
   </url>
   <url>
      <loc>http://localhost:55425/home/contact</loc>
   </url>
   <url>
      <loc>http://localhost/yourote/100</loc>
      <lastmod>2015-12-01</lastmod>
      <changefreq>always</changefreq>
      <priority>0.5</priority>
   </url>
</urlset>

Multiples SiteMaps

The same code above with this setting:

#!c#
EasySiteMapGenerator g = new EasySiteMapGenerator(new SiteMapConfig()
{
    Domain = @"localhost.com/",
    LocalFile = Server.MapPath("~"), //For development use [C:\your_pagetest]
    TotalItensByFile = 2
});
Will generate three files in the root: sitemap1.xml (with two urls), sitemap2.xml (with two urls) and sitemap_index.xml (with the path of the two sitemaps)

Contents of sitemap_index.xml:

#!XML

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

<sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <sitemap>
      <loc>localhost.com/sitemap1.xml</loc>
      <lastmod>2015-12-02</lastmod>
   </sitemap>
   <sitemap>
      <loc>localhost.com/sitemap2.xml</loc>
      <lastmod>2015-12-02</lastmod>
   </sitemap>
</sitemapindex>

Updated