开发者

Best way to create a dynamic Google Sitemap using ASP.NET MVC?

Is there a recommended approach for creating Google Sitemaps using ASP.NET MVC?

I'm new to MVC and this is the first time I've needed to create one and wondered how best to go about it.

I have a number of static links (About Us, FAQ's etc.) that I would like included within the sitemap, but then need the rest of it to be dynamically generated from articles that have been posted on the site.

开发者_如何转开发

Any advice/direction on how to create this would be much appreciated.


1 - The first thing you'll need is to create a representation of your entire website a list of nodes which have children, parents and so forth. The easiest way to do this without rolling your own solution is to use the MVCSiteMapProject. It allows you so use MVCish terms like your action and controller names to define nodes which will automatically have the correct urls using your routing definitions.

2 - Now because the MVCSiteMap inherits from the default XmlSiteMap (may not have the exact name right ) you can use another add in to generate a google sitemap from the nodes you've defined in the MVCSiteMapProject.

There a bunch of ways to do #2 so its up to you to decide the technique.


You could create a generic handler the same as web forms, but I'd be inclined to use a controller action and a custom route.

Some simple steps to follow might be:

  1. Create an action in your Home Controller (or create a new one), call it SiteMap.
  2. Have the action return a View with your page data as the model.
  3. Create a View called SiteMap that contains the Google XML, then iterate through your page data to generate the dynamic content.
  4. Add a custom route to your Global.asax file that points to "/sitemap.xml" or whatever and pre-populate your the controller and action parameters with that of your new action.

If you're unsure of custom routes, just copy the default one and paste it above. The routes are handled first come first serve. Make sure you give it a new name.

Rich


for dynamic sitemap, i found this is the best solution : http://ben.onfabrik.com/posts/generating-dynamic-xml-sitemaps-in-aspnet-mvc

it use a controller to generate the xml file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜