Filtering pages from EPiServer sitemap files in Auros.EPiSiteMap
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.