More in this section

Sitemap

3 posts, 0 answered
  1. syed
    syed avatar
    22 posts
    Registered:
    05 Mar 2009
    29 Jul 2009
    Link to this post
    Hi there

    Does anybody tell me how to create the sitemap like below:

    Parent > Pages

    Thanks
    syed
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    29 Jul 2009
    Link to this post
    Hi syed,

    Please take a look at XmlSiteMapProvider Class. In Sitefinity all cms pages are automatically added to the CmsSiteMapProvider, so if you are working with cms pages you do not have to create an additional provider.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Joe
    Joe avatar
    64 posts
    Registered:
    05 Jul 2012
    29 Jul 2009
    Link to this post
    This is the class that I use for the Southeast Valley .NET User Group site.

    using System; 
    using System.Collections; 
    using System.Web; 
    using System.Collections.Specialized; 
    using System.Text; 
    using System.Xml; 
    using Telerik.Cms; 
    using Telerik.Cms.Data; 
     
    namespace SEVDNUG.Web.HttpHandlers 
        /// <summary> 
        /// This <c>HttpHandler</c> will generate a Google Site Map 
        /// </summary> 
        public class GoogleSiteMapHandler : IHttpHandler 
        { 
            #region IHttpHandler Implementation 
            /// <summary> 
            /// Gets a value indicating whether another request can use the <see cref="T:System.Web.IHttpHandler"/> instance. 
            /// </summary> 
            /// <value></value> 
            /// <returns>true if the <see cref="T:System.Web.IHttpHandler"/> instance is reusable; otherwise, false. 
            /// </returns> 
            public bool IsReusable 
            { 
                get { return true; } 
            } 
     
            /// <summary> 
            /// Enables processing of HTTP Web requests by a custom <see cref="IHttpHandler"/> that implements the <see cref="T:System.Web.IHttpHandler"/> interface. 
            /// </summary> 
            /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> 
            public void ProcessRequest(HttpContext context) 
            { 
                try 
                { 
     
                    HttpResponse response = context.Response; 
                    response.ContentType = "text/plain"
     
                    XmlTextWriter writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8) 
                                               {Formatting = Formatting.Indented}; 
     
                    writer.WriteStartDocument(); 
                    writer.WriteStartElement("urlset"); 
                    writer.WriteAttributeString("xmlns""http://www.google.com/schemas/sitemap/0.9"); 
     
                    CmsManager manager = new CmsManager(); 
                    IRootPage root = manager.GetRootPage(); 
                    IList pages = root.Pages; 
     
                    foreach (CmsPage page in pages) 
                    { 
                        if (page.Navigable) 
                        { 
                            appendNode(page, writer, 0); 
                        } 
                    } 
     
                    writer.WriteEndElement(); 
                    writer.WriteEndDocument(); 
     
                    response.Flush(); 
                    writer.Flush(); 
                } 
     
                catch 
                { 
     
                } 
     
            } 
            #endregion IHttpHandler Implementation 
     
            private static void appendNode(CmsPage page, XmlWriter writer, int depth) 
            { 
                try 
                { 
                    writer.WriteStartElement("url"); 
                    writer.WriteElementString("loc", getURL(page)); 
                    writer.WriteElementString("lastmod", getLastMod(page)); 
                    writer.WriteElementString("changefreq", getChangeFreq(page)); 
                    writer.WriteElementString("priority", getPriority()); 
     
                    int subNodeDepth = depth + 1; 
                    foreach (CmsPage n in page.ChildPages) 
                    { 
                        if (page.Navigable) 
                        { 
                            appendNode(n, writer, subNodeDepth); 
                        } 
                    } 
     
                    writer.WriteEndElement(); 
                } 
     
                catch 
                { 
     
                } 
            } 
     
            private static string getURL(ICmsPage page) 
            { 
                try 
                { 
                    NameValueCollection vars = HttpContext.Current.Request.ServerVariables; 
                    string port = vars["SERVER_PORT"]; 
                    string protocol = vars["SERVER_PORT_SECURE"]; 
                    System.Web.UI.Control urlResolver = new System.Web.UI.Control(); 
     
                    if ((port == null | port == "80" | port == "443")) 
                    { 
                        port = ""
                    } 
                    else 
                    { 
                        port = ":" + port; 
                    } 
     
                    if ((protocol == null | protocol == "0")) 
                    { 
                        protocol = "http://"
                    } 
                    else 
                    { 
                        protocol = "https://"
                    } 
     
                    string url = page.DefaultUrl.Url; 
                    return protocol + vars["SERVER_NAME"] + port + urlResolver.ResolveUrl(url); 
                } 
     
                catch 
                { 
                    return string.Empty; 
                } 
            } 
     
            private static string getLastMod(IPage page) 
            { 
                try 
                { 
     
                    return page.DateModified.ToString("o"); 
                } 
                catch 
                { 
                    return string.Empty; 
                } 
            } 
     
            private static string getChangeFreq(IPage page) 
            { 
                try 
                { 
                    string intervalString = string.Empty; 
                    long intervalLong = Microsoft.VisualBasic.DateAndTime.DateDiff( 
                        Microsoft.VisualBasic.DateInterval.Hour, 
                        page.DateModified, 
                        DateTime.Now, 
                        Microsoft.VisualBasic.FirstDayOfWeek.System, 
                        Microsoft.VisualBasic.FirstWeekOfYear.System); 
     
                    if (intervalLong < 1) 
                    { 
                        intervalString = "hourly"
                    } 
                    else if (intervalLong <= 24 & intervalLong > 1) 
                    { 
                        intervalString = "daily"
                    } 
                    else if (intervalLong <= 168 & intervalLong > 24) 
                    { 
                        intervalString = "weekly"
                    } 
                    else if (intervalLong <= 672 & intervalLong > 168) 
                    { 
                        intervalString = "monthly"
                    } 
                    else if (intervalLong <= 8766 & intervalLong > 672) 
                    { 
                        intervalString = "yearly"
                    } 
     
                    return intervalString; 
                } 
                catch 
                { 
                    return string.Empty; 
                } 
            } 
     
            private static string getPriority() 
            { 
                try 
                { 
     
                    return "1"
                } 
                catch 
                { 
                    return string.Empty; 
                } 
            } 
     
        } 
    The add the following to the web config file underneath the httpHandlers section.
    <add verb="GET" path="SiteMap.ashx" type="SEVDNUG.Web.HttpHandlers.GoogleSiteMapHandler, SEVDNUG.Web.HttpHandlers"/> 

    You will then be able to use http://www.yourdomain.com/sitemap.ashx to display a sitemap.

    I hope to publish this in an article soon.
    Joseph Guadagno
    Sitefinity MVP
    Microsoft Visual C# MVP
    http://www.josephguadagno.net
Register for webinar
3 posts, 0 answered