forum

Home / DeveloperSection / Forums / Sitemap in Asp.Net MVC

Sitemap in Asp.Net MVC

Anonymous User215610-Oct-2014
'm trying to create an automatic sitemap ActionResult that outputs a valid sitemap.xml file. The actual generation of the file is not a problem, but I can't seem to figure out how to populate the list of URL's in the system. Here is the code I have so far:
publicContentResult Sitemap()
        {
            XNamespace xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9";
            XElement root = new XElement(xmlns + "urlset");
 
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter writer = new StreamWriter(ms, Encoding.UTF8))
                {
                    root.Save(writer);
                }
 
                return Content(Encoding.UTF8.GetString(ms.ToArray()), "text/xml", Encoding.UTF8);
            }
        }

For instance, suppose I have two controllers, and each controller has two actions associated with them:

HelpController

·    Edit

·    Create

AboutController

·         Company

·        Management

 


Updated on 10-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By