Tales from the Evil Empire

Bertrand Le Roy's blog

News


Bertrand Le Roy

BoudinFatal's Gamercard

Tales from the Evil Empire - Blogged

Blogs I read

My other stuff

Archives

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).

Attachment: GSiteMap1.1.zip
Posted: Dec 02 2005, 03:24 PM by Bertrand Le Roy | with 24 comment(s)
Filed under:

Comments

Bertrand Le Roy said:

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.
# December 5, 2005 2:41 PM

xgene said:

Downloaded this and it worked perfectly out the gate. Thanks much!
# November 1, 2006 3:42 PM

Ben said:

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

# December 18, 2006 2:05 PM

Pete said:

Where to get this now as i cant find it on the got dot net site ?
# May 18, 2007 11:20 AM

Bertrand Le Roy said:

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

# May 18, 2007 2:08 PM

Nic said:

I'm not awesome enough to convert this to VB. Is there potential for that?
# June 6, 2007 4:39 PM

Rafal said:

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?

# August 1, 2007 3:14 AM

Bertrand Le Roy said:

Rafal: I confirm that the site map stuff is now in Futures.

quickstarts.asp.net/.../searchsitemaps.aspx

# August 2, 2007 3:19 AM

Bertrand Le Roy said:

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.

# August 11, 2007 3:19 AM

Bertrand Le Roy said:

Steve: the Futures implementation can use any site map provider. Read this to learn how to implement your own:

msdn2.microsoft.com/.../system.web.sitemapprovider.aspx

# August 27, 2007 1:57 PM

WTF said:

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

# March 8, 2008 12:08 AM

Bertrand Le Roy said:

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

# March 10, 2008 12:48 PM

Karen said:

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

# April 1, 2009 10:58 AM

Bertrand Le Roy said:

@Karen: follow the link at the end of the post... Let me paste that here for you...

weblogs.asp.net/.../432188.ashx

# April 1, 2009 1:26 PM

will1968 said:

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

# July 16, 2009 4:01 PM

Speedbird186 said:

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?

# October 18, 2009 3:16 PM

Bertrand Le Roy said:

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

# October 18, 2009 3:43 PM

sking said:

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?

# January 1, 2010 12:57 AM

Bertrand Le Roy said:

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

# January 1, 2010 2:59 AM

Rajesh Singh said:

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

# January 6, 2010 6:28 AM

rtpHarry said:

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

# December 23, 2010 4:05 AM

Bertrand Le Roy said:

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

# December 23, 2010 4:17 AM

Tomas Crespo said:

The link www.asp.net/.../default.aspx doesn't works

# June 22, 2011 11:54 AM

Tomas Crespo said:

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

# June 22, 2011 1:16 PM