Google Sitemaps for ASP.NET 2.0

Google has a little-known feature that enables web site authors to tell the search engine about the structure of their site. ASP.NET also has a way of representing the structure of the site in a map. ASP.NET SiteMaps can be exposed on the site using a Menu, TreeView or SiteMapPath control, but there is no built-in feature that exposes this information in the format that Google understands.

That's why I've developed a small handler that scans the ASP.NET SiteMap and formats it into the Google XML format for site maps. Once you've copied this handler into your site, just register it as your site map with Google from this page:
https://www.google.com/webmasters/sitemaps

I've also added a very simple control that displays the ASP.NET SiteMap in a very plain HTML form (using h1...h6 tags) that is likely to be well indexed by most search engines. The control's look can be very much improved on and customized but I'll leave that as an exercise for the reader.

The sample also comes with a sample site to demonstrate the use of the control and handler.

Download the project from here:
http://www.gotdotnet.com/codegallery/codegallery.aspx?id=237330e0-65c5-4ebb-b62b-e486dd598604

UPDATE: I updated the handler so that it can now use Google-specific attributes. You can now specify additional information such as the update frequency of each page directly in the ASP.NET SiteMap (version 1.1 of the handler).

UPDATE 2: This implementation is now obsolete. This feature is now part of the ASP.NET Futures release with a much more complete implementation. Check it out!
http://www.asp.net/downloads/futures/default.aspx?tabid=62

UPDATE 3: I've added back the source code as an attachment for this post, for reference purposes (but I encourage everyone to use the Futures version).

24 Comments

  • Feel free to modify what you want. I'll also add the possibility to add the Google-specific information directly in the site map file.

  • Downloaded this and it worked perfectly out the gate. Thanks much!

  • Got here from Sitefinity 3. Great add-on I am going to give this a try shortly.

  • Where to get this now as i cant find it
    on the got dot net site ?

  • On GotDotNet, but the project has been obsoleted now that ASP.NET Futures have a similar, but much more complete feature.

  • I'm not awesome enough to convert this to VB. Is there potential for that?

  • how can the google Sitemap be done with Futures? It seems it only suppoorts Windows Live. It also talks only about searching your site, not sitemap...

    Does anybody has source code of this?

  • Rafal: I confirm that the site map stuff is now in Futures.
    http://quickstarts.asp.net/Futures/services/doc/searchsitemaps.aspx

  • Igor: the documentation is way better than what was available for this version (i.e. this blog post), see previous comment for a link.
    I can make the source code for this old project available here but I really encourage everyone to use the Futures version.

  • Steve: the Futures implementation can use any site map provider. Read this to learn how to implement your own:
    http://msdn2.microsoft.com/en-us/library/system.web.sitemapprovider.aspx

  • Update 1, Update 2, Update 3, sends you to a new page that says there is yet another update on another page....what's the deal....this page is a collosal waste of time

  • The page that the updates links to points you to another download for a completely different feature, not for sitemaps.

  • Is there any way to get this anymore? We are still using .net 2.0 so I can't use the futures implementation.

  • @Karen: follow the link at the end of the post... Let me paste that here for you...
    http://weblogs.asp.net/bleroy/attachment/432188.ashx

  • I have downloaded the latest zipped copy and got it working on my website. It looks good and google has accepted it.

    Is there anything I should be worried about?

    If not, thank you very much for some very useful code.

    Will


  • Has this actually made it into 3.5 SP 1? The futures download doesn't exist anymore, but I can't seem to figure out how to find it if it is built into the latest Framework release?

  • @speedbird186: it has not, but the source code is still available. It's attached to this post.

  • Hi Happy 2010!

    I was able to convert your .cs file to .vb with the exception of: return (o == null) ? 6 : (int)o;

    public class SiteMapView : WebControl {

           [DefaultValue(6)]

           public int MaxDepth {

               get {

                   object o = ViewState["MaxDepth"];

                   return (o == null) ? 6 : (int)o;

               }

               set {

                   ViewState["MaxDepth"] = value;

               }

    **********************************************

    Here's my VB code of the above:

    <DefaultValue(6)> _

               Public Property MaxDepth() As Integer

                   Get

                       Dim o As Object = ViewState("MaxDepth")

                   Return If((o Is Nothing), 6, CInt(o))

                   End Get

                   Set(ByVal value As Integer)

                       ViewState("MaxDepth") = value

                   End Set

               End Property

    ********************************************

    The word If is underlined in my visual studio saying expression expected. That syntax looks strange on the if statement. Any idea how to fix?

  • @sking: not sure what the point of translating it to VB is, but you may use iff instead of if.

  • Hello friends,

    I only wanted to know that, here anybody got success after submitting this sitemap to google webmaster.

    Means, Google webmaster has accepted this sitemap.

    Please reply,

    Thanks

    Rajesh Singh

    Asp.net Developer

    www.indianic.com

  • What happened with this? Didn't seem to ever make it into asp.net 3.5 sp1?

  • I'm not sure. The code for this is still available, and it's not too complex. Feel free to use it.

  • The link http://www.asp.net/downloads/futures/default.aspx?tabid=62 doesn't works

  • And now? With ASP.NET 4, is it posible to do this easy? or I need to use Bertrand method yet?

Comments have been disabled for this content.