Search code examples
sitecoreglass-mapper

Sitecore: How to customize media urls


I'm using sitecore 8.1 with Glassmapper and I want to customize the urls that are generated for images in my Media Library.

So my plan was to tap into the LinkProvider to achieve this, but it turns out that the LinkProvider is invoked only when I resolve a link in code, i.e. when I do something like this:

string url = Sitecore.Links.LinkManager.GetItemUrl(item); 

Just to be clean, I'm not trying to change the media prefix but I need to add some query string params to the url. I am hoping to achieve this by some provider/pipeline so that when the MVC view is generate the glassmapper model's Image.Src has the customized url.

Thanks!


Solution

  • The link provider by default does not handle media URLs this is handled by the MediaProvider.

    You'll need to implement your own MediaProvider for this and add logic to the method: GetMediaUrl().

    Glass will use the media provider to get the URL for the image.

    Great example here of how to put this together here:

    http://getfishtank.ca/blog/sitecore-7-2-upgrade-encoding-media-library-item-names