Hello,
I'm trying to build a custom URL Provider to turn a State query parameter into a country/state url (eg: http://rapido.localtest.me/Default.aspx?ID=123&State=CA turns into http://rapido.localtest.me/test/us/ca)
I started by doing a UrlProvider:
namespace Dna.Winnebago.UrlProviders { [EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [AddInName("Dealers by state id")] [AddInDescription("Generates urls for dealer Directory in the form /countrycode/statecode")] [AddInActive(true)] [AddInGroup("Dealer Directory")] [AddInTarget("QueryPublisher")] public class DealerDirectory : UrlProvider { public override List<Mapping> GetMappings() { var result = new List<Mapping>(); foreach (var country in Services.Countries.GetCountries()) { foreach (var state in country.Regions) { result.Add(new Mapping("State", state.RegionCode, $"{country.Code2}/{state.RegionCode}")); } } return result; } } }
However I had an issue because I only wanted to apply it to a single page. So, instead, I tried to create UrlDataProvider (aka the new URL provider)
using System; using System.Collections; using System.Collections.Generic; using Dynamicweb.Core; using Dynamicweb.Ecommerce; using Dynamicweb.Extensibility.AddIns; using Dynamicweb.Extensibility.Editors; using Dynamicweb.Frontend.UrlHandling; namespace Dna.Winnebago.UrlProviders { [AddInName("Dealer Directory")] [AddInOrder(1000)] public class DealerDirectoryNew : UrlDataProvider, IDropDownOptions { public override IEnumerable<UrlDataNode> GetUrlDataNodes(UrlDataNode parent, UrlDataContext dataContext) { var nodes = new List<UrlDataNode>(); foreach (var country in Services.Countries.GetCountries()) { foreach (var state in country.Regions) { nodes.Add(new UrlDataNode() { Id = $"DealerDirectory_{state.RegionCode}", ParentId = parent.Id, PathName = $"{country.Code2}/{state.RegionCode}", IgnoreInChildPath = false, IgnoreParentPath = false, // PathExact = $"{country.Code2}/{state.RegionCode}", QueryStringParameter = "State", QueryStringValue = state.RegionCode, QueryStringExact = string.Empty, IgnoreParentQuerystring = false }); } } return nodes; } public Hashtable GetOptions(string dropdownName) { var options = new Hashtable(); return options; } } }
This is working almost as expected except that the path name is converting the slash (/) to a dash (-). So I get http://rapido.localtest.me/test/us-ca instead of http://rapido.localtest.me/test/us/ca which is what I need to achieve. I tried using the path exact, which does keep the slash, however it loses the rest of the path, so I can't use that either.
Is there a way I can force the PathName to keep the slash and not change it to a dash? Or is there any way I can achieve what I'm trying to do which is convert http://rapido.localtest.me/Default.aspx?ID=123&State=CA to http://rapido.localtest.me/test/us/ca only in a specific page?
Thanks