Dynamic sitemap in ASP.NET MVC

前端 未结 7 914
小蘑菇
小蘑菇 2021-01-30 09:04

I\'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 o

7条回答
  •  忘了有多久
    2021-01-30 09:41

    I posted a do-it-yourself answer down below. But here is a package that does it out of the box for MVC sites:

    http://mvcsitemap.codeplex.com/ (<- old site, but with extensive documentation!)

    https://github.com/maartenba/MvcSiteMapProvider/wiki (<- moved to new site, lacking some documentation, and not as active)

    Note that it does a multitude of things:

    • Automagically registers itself in the Mvc routes to respond to SEO /sitemap.xml requests (even though there is no physical file for /sitemap.xml). This is completely compatible with all search engine robots I've found, as well as rolling over when it gets to 10,000, etc.
    • Comes with a set of partial views to use for BreadCrumb navigation built-in! We use this quite extensively, though the dynamic data portion is a bit cumbersome, it does work.
    • Comes with a set of partial views for Menu to be controlled as well.
    • Honors the [Authorize] security bits of your Controllers and Action methods.

    All of the above points are controlled from the single mvc.sitemap XML file you edit and configure. I've used this in a number of projects now to do 2 or 3 of the above points. Have it all configurable in 1 place, and dynamically generated, is really nice.

    Though I find the ability to create dynamic data providers a bit cumbersome (and grossly violates any type of IoC you wish to do), it does get the job done and scales nicely once you bypass their caching and use your own.

提交回复
热议问题