Sitefinity Toolkit: Sitemap
In the first post on my Sitefinity Toolkit series, I’ll be introducing the SiteMap Generator, which creates an ashx handler to automatically create an XML Sitemap. This can be submitted to Bing, Google, or any other search engine.
Download and install the Sitefinity Toolkit to your bin directory. Be sure to download the correct version for your Sitefinity installation!
You need to create a handler for the url /sitemap.ashx and map it to the Sitefinity Toolkit. Add the following to your web.config:
<system.web> <httpHandlers> <add verb="GET" path="/sitemap.ashx" type="SelArom.Net.Sitefinity.HttpHandlers.SiteMap" /> </httpHandlers> </system.web>
If you are using IIS7, be sure to include this under system.webserver as well:
<system.webServer> <handlers> <add name="Sitemap" verb="GET" path="/sitemap.ashx" type="SelArom.Net.Sitefinity.HttpHandlers.SiteMap" /> </handlers> </system.webServer>
Now all you have to do is navigate to yoursite/sitemap.ashx and your sitemap should load. Here is the sitemap for this site.
The Sitemap is built by parsing all pages in your sites tree. However, in addition, it can also navigate through the Events, News, Blogs, and Generic Content modules and add those pages to your sitemap.
NOTE: as of version 1.0, only the Default Provider for each generic content module is read. If you have more than one provider for each module, only the one listed as default will be included in your sitemap. If enough people request this feature (and perhaps kick in a few bucks to my studio fund, see sidebar) I’d be happy to extend this functionality to other providers.
In order for this to function properly, you need to define the url for the “details” page of each module. This is the page that holds the “detailsview” for the individual modules. This url needs to be defined in the appSettings node of web.config, using the Provider Name ending with “Url” as the key and the value being the url prefix for the details page.
For example, my Blog posts are prepended by “/blog” (look at the url for this page as an example. Also, my Software section uses the Generic Content module, and the url for those posts are prepended with “/software“. So my web.config looks like this:
<appSettings> <add key="BlogsUrl" value="/blog" /> <add key="SoftwareUrl" value="/software" /> </appSettings>
On this site, the default provider for the Blog Module is “Blogs” and the default provider for the Generic Content Module is “Software”. Therefore I use the keys “BlogsUrl” and “SoftwareUrl” to define the url prefixes for these posts. If you were including events and news, your appsettings might look like this:
<appSettings> <add key="EventsUrl" value="/calendar/event" /> <add key="NewsUrl" value="/news/default" /> </appSettings>
It just depends on what page you have defined to hold the detailsview for these modules, as well as the name of your default provider. If you do not define these keys, the sitemap will simply skip over these modules and proceed to the next one.
And that’s all there is to it! Give it a try, and please let me know your results. If you encounter any issues, have any suggestions or comments, please send them to firstname.lastname@example.org. And if you like my work, please consider donating to my studio fund through the widget on the sidebar!
Next time, I’ll be going over the Lowercase Urls feature that ensures that any non-lowercase urls are automatically 301 redirected to the lowercase version. Stay tuned for more!
Latest posts by selaromdotnet (see all)
- Restarting a Specific Azure Web App Instance - January 13, 2021
- Adding Ratings and Reviews to Sitecore Commerce with YotPo - November 13, 2018
- Sourcetree Suddenly Prompting for Github Credentials - February 22, 2018