Filtering pages in EPiSiteMap module for EPiServer is very simple. The module re-uses the EPiServer page filtering implementation to enable you to filter pages from the generated xml sitemap files based upon any logic that you require.
To implement your own page filters, there are two steps required.
- Create a class for the filter which implements EPiServer.Filters.IFilter.
- Decorate the class with the attribute Auros.EPiSiteMap.Filters.SiteMapFilter.
When the Sitemap job is run, the module will look for any filters using the above interface and class attribute. All pages in the site will then be passed through these filters before considered for inclusion in an xml sitemap file.
There are already a number of filters which are built into the module and run by default on the pages. These are:
- FilterPublicAccess - Filters pages which do-not have public access.
- FilterContainerPages - Filters container pages so they are not added to the sitemap.
- FilterPagesByLinkType - Filters pages which have a link type of either external, shortcut or inactive.
When creating our own page filters, we have to be aware that when the job runs on a schedule, the job will be running with no HTTP context.
An example of this is when we are required to filter secure pages from the sitemap files. We cannot use EPiServers FilterPagesForVisitor filter as this relies upon HttpContext.Current to assert the currents users access. To work around this, we can mock an anonymous visitor with 'everyone' access and assert the security check against the pages access control list.
We would like to share a new module for creating xml sitemap files we have recently been working on for EPiServer websites. Whilst there are already available a number of sitemap add-ons for EPiServer, we kept finding they didn't completely satisfy all of our requirements. What we really wanted was a solution which:
- Enables website administrators to manage the sitemap files to be created.
- Can be used in a simple, single website to complex multisite/enterprise configurations.
- Enables the languages to be selected for inclusion in a particular sitemap file.
- Has an interface which administrators can use to control the configuration.
- Can be run as a scheduled job.