Removing Appended Query Strings When Using Archive and Categories Widget in Sitefinity CMS

April 19, 2013 Digital Experience

When filtering content items in Sitefinity CMS using both categories/tags widget and archive by query, a string gets appended to the previous query string. This blog post explores how you can remove it.

By default archive and categories/tags widgets work with UrlPath which is by default configured on each widget against with filtering can be performed: 

site.com/page/year=2013/month=04/day=02

The problem doesn`t appear when filtering using UrlPath.

When UrlPath is changed to QueryString by editing a widget, go to advanced properties->UrlEvaluationMode and set it form UrlPaht to QueryString. Here is a screenshot.

The widgets will provide the filtering functionality by appending a query string to the current page URL.

The problem comes when  both archive and categories/tags widget perform filtering together.

First, filter with the archive widget and the URL gets filtered by date: 

site.com/page?year=2013&month=04&day=02

As a next step, filter with the categories/tags widget and the category/tag filter gets appended to the archive query string:

site.com/page?year=2013&month=04&day=02&taxonomy=categories&propertyName=category&taxon=%2fproducts

This appending is used to filter based on the criteria on both the archive and the taxonomy control tough in some cases this is not needed. To overcome this, create custom archive and categories widgets that remove the already existing query string when filtering.

Attached is the source of those controls.

The logic that clears the query string is located in CustomDateEvaluator.cs for the archive control and in CustomTaxonEvaluator.cs for categories control.

case UrlEvaluationMode.QueryString:
                    var yearFullUrlKey = String.Concat(urlKeyPrefix, "year");
                    var monthFullUrlKey = String.Concat(urlKeyPrefix, "month");
                    var dayFullUrlKey = String.Concat(urlKeyPrefix, "day");
                    var qString = QueryStringBuilder.Current.Reset();

 

To install the new widgets add the attached classes in your Sitefinity project and compile it.

 Go to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->NavigationToolboxsection->Tools create new and in the textbox fill in the class for the new archive control.

In the case with the namespace for the classes attached: 
Control CLR Type or Virtual Path: SitefinityWebApp.CustomArchive
Controller CLR type:CustomArchive
Name:CustomArchive
Title: New Archive Control

Save changes and the new archive control is ready for use.

For categories control go to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->NavigationToolboxsection->Tools create new and in the textbox fill in the class for the new archive control.

In the case with the namespace for the classes attached: 
Control CLR Type or Virtual Path: SitefinityWebApp. CustomTaxonomyControl
Controller CLR type: CustomTaxonomyControl
Name: CustomTaxonomyControl
Title: New Categories Control

Save changes and the new categories/tags control is ready for use.

 

The Progress Team