ASP.NET expose Web.sitemap as sitemap.xml
Does ASP.NET support exposing Web.sitemap as a sit开发者_如何学编程emap.xml for google to use?
Not out of the box, but it certainly is possible.
Basically, to tackle this project, you will need to break it down into the following phases.
- Get ASP.NET to intercept the sitemap.xml request
- Transpose everything which you have in the site map provider into the XML format.
- Spit out the XML format.
To get step 1 done, you need to do research on how to do this based on the IIS version you will be hosting in. IIS6 and IIS7 Classic mode will yield different implementation logic for IIS7 Integrated mode... more hoops to go through for the former IIS server configurations.
Once you have a request going through ASP.NET process where you are able to wire up a HTTP handler, or if you are using MVC, a route, then you are able to proceed with pumping out the XML.
First step would be able to transpose the data in your web.sitemap file. To do this, you need to access the SiteMap class. (http://msdn.microsoft.com/en-us/library/system.web.sitemap_members(v=VS.85).aspx).
Then lastly, you just need to spit it out. Maybe just use Linq to XML for it... but that is just a pretty straight forward task.
精彩评论