Click here to Skip to main content
15,897,032 members
Articles / Web Development / ASP.NET

ASP.NET Google Site Map Provider

Rate me:
Please Sign up or sign in to vote.
2.40/5 (4 votes)
10 Oct 2006CPOL9 min read 94.5K   2.7K   43  
Using the ASP.NET Provider model to generate a dynamic Google Sitemap.
/*
 * 
 * iFinity Smart Business Solutions - http://www.ifinity.com.au
 * Copyright (c) 2006
 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the "Software"), the rights to use, copy, modify, merge, publish, distribute, sublicense
 * copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
 * following conditions:

 * 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 *    of the Software.  
 * 2. The software may not be claimed as the original work of anyone other than the author and may not be sold as 
 *    a stand alone product

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 * 
 */

using System;
using System.Collections.Generic;
using System.Text;

using System.Web.Configuration;
using System.Configuration.Provider;

namespace iFinity.Providers.GoogleSiteMap
{
    public class GoogleSiteMapService
    {
        private static GoogleSiteMapProvider _provider = null;
        private static GoogleSiteMapProviderCollection _providers = null;
        private static object _lock = new object();

        public static string GetGoogleSiteMap(string siteURL)
        {
            //ensure providers are loaded
            LoadSiteMapProviders();
            //delegate to the default provider
            return _provider.GetGoogleSiteMap(siteURL);
        }
        private static void LoadSiteMapProviders()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    //double check provider still null
                    if (_provider == null)
                    {
                        //get reference to GoogleSiteMaps section
                        GoogleSiteMapSection section = (GoogleSiteMapSection)WebConfigurationManager.GetSection("googlesitemaps");

                        //load the registered providers and point _provider to default provider
                        _providers = new GoogleSiteMapProviderCollection();
                        ProvidersHelper.InstantiateProviders(section.Providers, _providers, typeof(GoogleSiteMapProvider));
                        _provider = _providers[section.DefaultProvider];

                        if (_provider == null)
                        {
                            throw new ProviderException("Unable to load default GoogleSiteMapProvider");
                        }
                    }
                }
            }

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager DNN Corp
Australia Australia
Bruce Chapman is the Product Manager for Cloud Services at DNN. He’s been an active member of the DNN Community since 2006 as a contributor, vendor and now employee of DNN Corp.

You can read his blog at http://dnnsoftware.com/blog or follow him on Twitter @brucerchapman

Comments and Discussions