ASP.NET AJAX Community
The Microsoft ASP.NET technologies platform combined with AJAX technologies enables you to build rich, interactive and user-friendly web applications.

Google Sitemap made easy

Jan's Blog

Syndication

Archives

Hi,

Because I like to do things the easy way I created this GSitemap class to easily create Google sitemaps.

In Visual Studio add a reference to the GSitemap.dll and create a new General Handler, for example called GoogleSitemap.ashx.

Use the following code in your handler: 

using System;
using System.Web;

public class GoogleSitemap : IHttpHandler 
{
    public void ProcessRequest (HttpContext context) 
    {
        GSitemap.GSitemap map = new GSitemap.GSitemap(ref context);
        map.AddNode("http://www.example.com/index.html");    
        map.AddNode("http://www.example.com/contact.html");
        map.AddNode("http://www.example.com/privacystatement.html");
        map.AddNode("http://www.example.com/generalterms.html");
        map.WriteContext();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}

Run GoogleSitemap.ashx and it will return the Google sitemap XML.

<siteindex xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.google.com/schemas/sitemap/0.84/siteindex.xsd">
  <sitemap>
    <loc>http://www.example.com/index.html</loc> 
    <lastmod>2008-06-14</lastmod> 
  </sitemap>
  <sitemap>
    <loc>http://www.example.com/contact.html</loc> 
    <lastmod>2008-06-14</lastmod> 
  </sitemap>
  <sitemap>
    <loc>http://www.example.com/privacystatement.html</loc> 
    <lastmod>2008-06-14</lastmod> 
  </sitemap>
  <sitemap>
    <loc>http://www.example.com/generalterms.html</loc> 
    <lastmod>2008-06-14</lastmod> 
  </sitemap>
</siteindex>


Now submit the your GoogleSitemap.ashx in Google.

That's all there is to it...

If you wish to have the GSitemap.dll source code Visual Studio 2005 project, just leave me a note.

Regards,

Jan.


Posted jun 16 2008, 07:23 by stolk_jan
Filed under: , ,
Attachment: GSitemap.zip

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Copyright (c) 2008 by ASPNETAJAX.COM
Powered by Community Server (Non-Commercial Edition), by Telligent Systems