Need to make this C# file include "details" when generating Google Sitemap file with .ashx file

The attached C# file currently builds a Google friendly sitemap file out of a web.sitemap file. Unfortunately it is only grabbing the url and Title, it doesnt include the description or the modified date or crawl rate.

Does anyone know how to have this file grab that data too?

Thanks
public class gsitemap1 : IHttpHandler
    {
        private const int MaxDepth = 6;

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse response = context.Response;
            response.ContentType = "text/xml";

            using (XmlTextWriter writer = new XmlTextWriter(response.OutputStream, Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset");
                writer.WriteAttributeString("xmlns", "http://www.google.com/schemas/sitemap/0.84");
                SiteMapNode root = SiteMap.RootNode;
                WriteNode(root, writer, 0);
                writer.WriteEndElement(); // urlset
                writer.WriteEndDocument();
            }
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        private void WriteNode(SiteMapNode node, XmlTextWriter writer, int depth)
        {
            if (depth > MaxDepth) return;

            writer.WriteStartElement("url");

            NameValueCollection vars = HttpContext.Current.Request.ServerVariables;
            string port = vars["SERVER_PORT"];
            port = (port == "80") ? String.Empty : ':' + port;
            string protocol = (vars["SERVER_PORT_SECURE"] == "1") ? "https://" : "http://";
            writer.WriteElementString("loc", protocol + vars["SERVER_NAME"] + port + node.Url);

            string lastMod = node["lastModified"];
            if (String.IsNullOrEmpty(lastMod))
            {
                try
                {
                    string physicalPath = HttpContext.Current.Request.MapPath(node.Url);
                    if (File.Exists(physicalPath))
                    {
                        DateTime lastModified = File.GetLastWriteTimeUtc(physicalPath);
                        lastMod = lastModified.ToString("yyyy-MM-ddThh:mm:ss.fffZ");
                    }
                }
                catch { }
            }
            if (!String.IsNullOrEmpty(lastMod))
            {
                writer.WriteElementString("lastmod", lastMod);
            }

            string changeFreq = node["changeFrequency"];
            if (!String.IsNullOrEmpty(changeFreq))
            {
                writer.WriteElementString("changefreq", changeFreq);
            }

            string priority = node["priority"];
            if (!String.IsNullOrEmpty(priority))
            {
                writer.WriteElementString("priority", priority);
            }

            writer.WriteEndElement(); // url

            int subNodeDepth = depth + 1;
            foreach (SiteMapNode subNode in node.ChildNodes)
            {
                WriteNode(subNode, writer, subNodeDepth);
            }
        }
    }

Open in new window

LVL 4
DotNetChanoAsked:
Who is Participating?
 
Kamal KhaleefaInformation Security SpecialistCommented:
try to remove the if statement for them and always include it

  writer.WriteElementString("changefreq", changeFreq);

    writer.WriteElementString("priority", priority);
and you set the changeFreq and priority manually
ex:
priority=0.9
changeFreq=daily
0
 
DotNetChanoAuthor Commented:
No body knows how to fix this?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.