Users Pricing

forum

Home Forums Sitemap in Asp.Net MVC – MindStick

Sitemap in Asp.Net MVC

Anonymous User 2986 10 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:
public ContentResult 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

 


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md