If I create a class inheriting the DefaultMediaUrlProvider in order to override GetMediaUrl, I can't get it to kick in.
The code looks like this(have not implemented logic, as I would like to see it kick in first)
ImgIxUrlProvider.cs
public class ImgIxUrlProvider : DefaultMediaUrlProvider
{
public override UrlInfo GetMediaUrl(UmbracoContext umbracoContext, IPublishedContent content, string propertyAlias, UrlMode mode,
string culture, Uri current)
{
return base.GetMediaUrl(umbracoContext, content, propertyAlias, mode, culture, current);
}
}
ImgIxUrlProviderComposer.cs
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ImgIxUrlProviderComposer : IUserComposer
{
public void Compose(Composition composition)
{
// no luck
composition.MediaUrlProviders().Replace<DefaultMediaUrlProvider, ImgIxUrlProvider>();
// no luck
composition.MediaUrlProviders().Insert<ImgIxUrlProvider>();
}
}
If I set a breakpoints in my Composer.Compose method and one in ImgIxUrlProvider.GetMediaUrl, only the Composer.Compose gets hit. Setting one in GetMediaUrl does not get hit. So something is not wireing up as I would expect.
My goal is to replace the default media URL with ImgIx(cdn) url.
I'm aware this is an old thread, but I found it while I was looking to change the media domain and thought this may help future internet wanderers.
Umbraco now have a package that deals with external media providers and have this very setting (CDN Provider) which you can setup to change the domain.
Here's the function that activates it, ran after the composers:
Custom MediaUrlProvider - Override DefaultMediaUrlProvider.GetMediaUrl
Umbraco version: 8.1.5
Hi,
If I create a class inheriting the DefaultMediaUrlProvider in order to override GetMediaUrl, I can't get it to kick in.
The code looks like this(have not implemented logic, as I would like to see it kick in first)
ImgIxUrlProvider.cs
ImgIxUrlProviderComposer.cs
If I set a breakpoints in my Composer.Compose method and one in ImgIxUrlProvider.GetMediaUrl, only the Composer.Compose gets hit. Setting one in GetMediaUrl does not get hit. So something is not wireing up as I would expect.
My goal is to replace the default media URL with ImgIx(cdn) url.
Can you see what I am missing?
//casper
I'm aware this is an old thread, but I found it while I was looking to change the media domain and thought this may help future internet wanderers.
Umbraco now have a package that deals with external media providers and have this very setting (CDN Provider) which you can setup to change the domain.
Here's the function that activates it, ran after the composers:
https://github.com/umbraco/Umbraco.StorageProviders/blob/582b15dea54ed07567be5feebdcbfa71e18fd328/src/Umbraco.StorageProviders/DependencyInjection/CdnMediaUrlProviderExtensions.cs#L71
is working on a reply...