SaaS CMS has officially launched! Learn more now.

CMS 12 migration - breaking change with RouteCollection.MapAssetRoutes

Vote:
 

Hello,

In v11, we had a custom route for our assets in our Global.asax. We are trying to find an equivalence in v12.

This was our original code:

routes.MapAssetRoutes(
    name: "PublishingImages",
    url: "/{node}/{partial}/{action}",
defaults: new { action = "index" },
staticSegmentPlaceHolder: EPiServer.Web.Routing.RouteCollectionExtensions.MediaStaticSegmentPlaceHolder,
globalReplacement: "publishingimages",
siteReplacement: EPiServer.Web.Routing.RouteCollectionExtensions.SiteAssetStaticSegment);

Any suggestions?

#320169
Apr 08, 2024 15:11
Vote:
 

What are you trying to achieve with that route? There might be better ways of solving your requirement. 

Routing has changed a lot between .NET Framework and .NET Core.

#320170
Apr 08, 2024 16:40
Vote:
 

Thanks for the reply Johan.

We are storing assets in the CMS and we would like to remove the globalassets portion of the url. We are using this as a safety net from our old website.

before, right now it's /globalassets/publishingimages and we want /publishingimages

In CMS 11, we were achieving this with the above code.

#320172
Apr 08, 2024 17:07
Vote:
 

Hi OlivierG,

I believe you can achieve what you're looking for with:

public sealed class PublishingImagesRouteRegistration : IContentRouteRegister
{
    public ContentRouteDefinition ContentRouteDefintion => new ()
    {
        Name = nameof(PublishingImagesRouteRegistration),
        RouteRootResolver = s => s.GlobalAssetsRoot,
        ContextMode = RouteContextMode.All,
        SupportMultiLanguage = false,
        StaticSegments = new[] { "publishingimages" },
    };
}


you need to register this in services with:

services.AddTransient<IContentRouteRegister, PublishingImagesRouteRegistration>();


I've tested in briefly in Alloy, but more extensive tests will be needed on your side.

#320328
Apr 11, 2024 13:16
Vote:
 
#320369
Apr 12, 2024 4:08
Vote:
 

1 vote for Karol Berezicki. Yes, it is break change with routing in CMS 12. We can add more implementation for IContentRouteRegister to register route. I saw this code works in Alloy. The default route for global assets is replaced by new one.

#320474
Edited, Apr 14, 2024 8:43
* 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.