November Happy Hour will be moved to Thursday December 5th.

Change globalassets route

Vote:
 

I was searching for a way to edit the path of all media files (change 'globalassets' into 'media') and stumbled upon this forum post
I'm actually surprised it got so little attention, I would assume that more developers have come across this requirement.

The solution as mentioned in the post is quite brief. I understand it's a matter of replacing the existing routing for assets to a new one, changing the static segment along the way.
But my question is: how do I know which one is the routing for the assets, the one I need to replace?

I tried removing several of the routings, assuming at some point to see broken images, but this didnt happen.

Does anyone have some good pointers on how to set this up? Apart from the ones already mentioned in the other post...

Cheers, Reinder

#150866
Edited, Jun 30, 2016 16:25
Vote:
 

Hi

Below is an example of an override of RegisterRoutes in Global.asax.cs that does the replacement of media route

 protected override void RegisterRoutes(System.Web.Routing.RouteCollection routes)
        {
            base.RegisterRoutes(routes);
            int mediaRouteIndex = 0;
            //Find out index of media route so we can replace it at same location
            for (int i =0 ; i <routes.Count; i++)
            {
                var contentRoute = routes[i] as ContentRoute;
                if (contentRoute != null && contentRoute.Name.Equals("Media_Global"))
                {
                    mediaRouteIndex = i;
                    break;
                }
            }

            if (mediaRouteIndex != 0)
            {
                routes.RemoveAt(mediaRouteIndex);
                routes.MapContentRoute(
                    name: "Media_Global",
                    url:  "media/{node}/{partial}/{action}",
                    defaults: new { action = "index" },
                    contentRootResolver: sd => sd.GlobalAssetsRoot);
                //The media route is now added last, move it to previous location
                var mediaRoute = routes.Last();
                routes.RemoveAt(routes.Count - 1);
                routes.Insert(mediaRouteIndex, mediaRoute);
            }
        }
#150875
Jul 01, 2016 9:26
Vote:
 

Thanks Johan, works like a charm!

#150912
Jul 01, 2016 15:24
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.