views:

43

answers:

1

I have a controller on my site that handles unknown actions and returns a view if it exists. This is so that static content can be added to this particular area of the site without having to modify the controller. The problem I am faced with now is to create a sitemap.xml file that contains links to all of these "unknown" views. What is the best method of enumerating these static content views from my method which is generating the site map?

The code below shows what I am doing for the unknown actions:

protected override void HandleUnknownAction(string actionName)
{
    GetUnknownActionResult(actionName).ExecuteResult(ControllerContext);
}

[NonAction] //public so it is testable
public ActionResult GetUnknownActionResult(string actionName)
{
    var result = View(actionName);

    if (result.ViewEngineCollection.Any(engine => engine.FindView(ControllerContext, result.ViewName, null, true).View != null))
    {
        return result;
    }

    return new HttpNotFoundResult();
}
A: 

If you are serving static content such as .htm files and .pdf files from a "static content" directory, I would just use System.File.IO to enumerate those files, and build your links from that.

Robert Harvey
These aren't truly static content since they are views using a master page. I have no problem using System.File.IO to read the directory, but I was hoping there was a better way to enumerate the views.
mkedobbs
There is an XML Sitemap Helper here: http://www.asp-net-mvc.com/MvcHelpers/XmlSitemap, but I don't know if it applies to your situation.
Robert Harvey