user822211
user822211

Reputation: 353

How change "MediaLinkPrefix" Programmatically in sitecore?

I know "MediaLinkPrefix" can be changed in web.config. But is it possible to change "MediaLinkPrefix" Programmatically? Thanks!

Upvotes: 1

Views: 572

Answers (2)

Sean Kearney
Sean Kearney

Reputation: 4008

To answer your specific question. No. You cannot programmatically change the value of that setting.

If you are trying to use Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaItem) to get the URL of a MediaItem then that is leveraging the Sitecore.Resources.Media.MediaProvider, which pulls the value of the MediaLinkPrefixfrom the Sitecore.Resources.Media.MediaConfig class. That property does not have a 'setter'. Furthermore, the value of that property actually comes from Sitecore.Configuration.Settings.Media.MediaLinkPrefix, which also doesn't have a setter and is pulled directly from the config file.

The MediaManager is a static class that I believe isn't able to be swapped out with a custom implementation. And, unlike the LinkManager, the MediaManager is hard coded to use the Sitecore.Resources.Media.MediaProvider so you can't write a custom provider either.

Upvotes: 2

Ruud van Falier
Ruud van Falier

Reputation: 8877

You can do this by creating your own implementation of Sitecore.Links.LinkProvider and set it up in your web.config under the <linkManager> section.

I don't know the exact implementation, but you can inherit a class from Sitecore.Links.LinkProvider and then override the GetItemUrl() method. Then configure your class to be used as LinkManager.

Upvotes: 1

Related Questions