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();
}
mkedobbs
  • 4,327
  • 2
  • 23
  • 28
  • 1
    Static content? Why didn't you just put it in the content folder (or a subfolder thereof) as an htm file? – tvanfosson Feb 03 '10 at 20:28
  • The content is not truly static, as it needs to be displayed in the context of a master page (which itself has dynamic elements). Although, maybe the issue is a design one and I should consider loading the HTML into the master. Doesn't change the question though... would still like to know the "best" way to enumerate the views that are associated with a particular controller. Right now, I've resorted to just Server.MapPath() with a hard-coded string to the view folder. If this is the best way, so be it. – mkedobbs Feb 07 '10 at 02:05

1 Answers1

1

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
  • 178,213
  • 47
  • 333
  • 501
  • 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 Feb 03 '10 at 20:32
  • 1
    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 Feb 03 '10 at 20:36