No response yet, so i'll add some details... I've tried a few things, i think i'm close, but so far no cigar! Has anyone done this already? think i'm just missing something obvious!
i saw this...
"During outgoing URL generation are the events CreatingVirtualPath and CreatedVirtualPath raised where event handlers can modify the URLs generated
An alternative could be to hook up to event ContentRoute.CreatedVirtualPath and modify the generated Url.
This would probably be a good approach if you have an easy recogizable pattern of the url you want to modify."
so i created an IInitializableModule - added an eventhandler ContentRoute.CreatedVirtualPath += CreatedVirtualPath;
void CreatedVirtualPath(object sender, UrlBuilderEventArgs e)
{
if(e.UrlBuilder!=null)
{
if(e.UrlBuilder.Path.StartsWith("markets/"))
{
e.UrlBuilder.Path = e.UrlBuilder.Path.Replace("markets/","");
}
}
}
that certainly changed the urls - but just left me with 404 errors
also tried a segment, do i need to implement GetVirtualPathSegment? i couldnt work out how i could reformat the url in there
in global.asax.cs
protected override void RegisterRoutes(RouteCollection routes)
{
var segment = new MyCustomSegment("customnode");
var routingParameters = new MapContentRouteParameters()
{
SegmentMappings = new Dictionary<string, ISegment>()
};
routingParameters.SegmentMappings.Add("customnode", segment);
routes.MapContentRoute(
name: "customrouting",
url: "{language}/{customnode}/{partial}/{action}",
defaults: new { action = "index" },
parameters: routingParameters);
base.RegisterRoutes(routes);
}
public class MyCustomSegment : SegmentBase
{
public MyCustomSegment(string name)
: base(name)
{
}
public override string GetVirtualPathSegment(
System.Web.Routing.RequestContext requestContext,
System.Web.Routing.RouteValueDictionary values)
{
return null;
}
public override bool RouteDataMatch(SegmentContext context)
{
var segmentPair = context.GetNextValue(context.RemainingPath);
if (segmentPair.Next.Equals("markets"))
{
string path = context.RemainingPath.ToString();
context.RemainingPath = segmentPair.Remaining;
UrlBuilder urlBuilder = new UrlBuilder(url);
object pageReference;
Global.UrlRewriteProvider.ConvertToInternal(urlBuilder, out pageReference);
context.RoutedContentLink = pageReference;
return true;
}
return false;
}
}
Hi guys
Have you taken a look at Magnus' post on Routing context aware links in Commerce catalog? It was written for EPiServer commerce catalog routing but may point you in the right direction on how to set up custom routes for your needs.
David
Hi Guys
i've been struggling to get some custom routing working.
Basically i need to remove various elements from the url for more friendly urls...
so for example instead of /markets/insurance/products/motor/... and /markets/insurance/products/home/.. etc i just have /insurance/motor/.. /insurance/home/.. etc
there are a few threads about routing but none of them provide enough for me to get a solution working. I've already had a good look at these http://joelabrahamsson.com/custom-routing-for-episerver-content/ http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=68317 http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/7/Routing/Routing/ http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=65422
I'd be really grateful if someone could provide some pointers or code examples
many thanks