Skip to content

Instantly share code, notes, and snippets.

@MattisOlsson
Last active August 29, 2015 14:21
Show Gist options
  • Save MattisOlsson/70377e459de2736ab818 to your computer and use it in GitHub Desktop.
Save MattisOlsson/70377e459de2736ab818 to your computer and use it in GitHub Desktop.
Commerce routing fix
public class Global : EPiServer.Global
{
protected override void RegisterRoutes(RouteCollection routes)
{
base.RegisterRoutes(routes);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Move commerceeditpageroot route right before editpageroot route
// to fix issue with block preview and languages. Why?!
MoveCommerceEditPageRootRoute(routes);
}
private static void MoveCommerceEditPageRootRoute(RouteCollection routes)
{
var editPageRootRoutePos = GetEPiServerEditPageRootRouteIndex(routes);
if (editPageRootRoutePos > -1)
{
var commerceEditPageRootRoute = GetCommerceEditPageRootRoute(routes);
if (commerceEditPageRootRoute != null)
{
routes.Remove(commerceEditPageRootRoute);
routes.Insert(editPageRootRoutePos - 1, commerceEditPageRootRoute);
}
}
}
private static int GetEPiServerEditPageRootRouteIndex(RouteCollection routes)
{
var editPageRootRoute = routes["editpageroot"];
if (editPageRootRoute != null)
{
return routes.IndexOf(editPageRootRoute);
}
return -1;
}
private static RouteBase GetCommerceEditPageRootRoute(RouteCollection routes)
{
return routes["commerceeditpageroot"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment