Last active
August 29, 2015 14:21
-
-
Save MattisOlsson/70377e459de2736ab818 to your computer and use it in GitHub Desktop.
Commerce routing fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Global : EPiServer.Global | |
{ | |
protected override void RegisterRoutes(RouteCollection routes) | |
{ | |
base.RegisterRoutes(routes); | |
RouteConfig.RegisterRoutes(RouteTable.Routes); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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