Filtering pages from EPiServer sitemap files in Auros.EPiSiteMap
Tags: Development, EPiServer
Posted by: Adam Jenkin
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.
Stian - October 22nd, 2012 - 11:23
Hi!
I just tried this tool and it works like a charm! Thank you for making it available to the public.
I just wanted to let you know about one minor issue though: the formatting of the priority tag value is not accepted by Google Webmaster Tools as it requires a dot and not a comma. E.g. 0,5 needs to be converted 0.5 before it is accepted as a valid sitemap-file.
Regards
Stian
Adam Jenkin - October 25th, 2012 - 14:00
Thanks Stian – Glad your finding it useful!
I guess the issue with the priority value is occurring as the thread culture the job is running in formats decimals with a comma.
I’ll try to get this issue resolved with the next set of work I do on the module.
Adam
Øyvind - January 18th, 2013 - 12:45
Worked like a charm to install and set up. Thanx for sharing!
Øyvind - January 23rd, 2013 - 14:19
Hi. Have you done the dot / comma changes yet ? Get the same error as Stian did. Do not want to change the decimal settings on the server :-/
Adam Jenkin - January 29th, 2013 - 12:20
Hi Stian / Øyvind – The issue with the formatting of the priority value has been fixed. There is a new version of the module at codeplex which you can install over the top of the existing through the deployment centre.
let me know how you get on.
Thanks