When to use UrlMode.Absolute on GetCropUrl?
# help-with-umbraco
o
Hey there - I'm using Image.GetCropUrl("thumbnail", UrlMode.Absolute) on a website but the site has been put behind Azure Front Door and image stopped working. If I removed UrlMode.Absolute, the images work again. When should UrlMode.Absolute be used and when shouldn't it be used? Not much in the docs that was any help. 🙂
s
Absolute URLs are just the full URL including protocol and domain name. I'd say pretty rare for it to be required when relative URLs work just fine (relative is just
/media/etc..
).
n
UrlMode.Absolute is needed for Meta tag links to images, e.g. Open Graph image. Relative Urls are find for img tags / download links etc. This is because Open Graph / Meta tag processors need the domain to be part of the URls else they fail validation.
s
Good point!
Not sure why Frontdoor blocks this?
n
Yeah that does seem odd.
s
Different domain name from the one the rest of the site is on maybe?
n
Also... I think, and I could be wrong, if you are using a CDN for your image cache, then it puts the full URL in as well no matter what type of link you add ... but that's a bit of speculation as I've not been in that situation, just based on things I've seen
d
If you get the wrong absolute URL in your content when requesting one, you might be missing your forwarded headers middleware. frontdoor and CDN services usually send X-Forwarded-[...] headers and you need to use forwarded headers middleware in order for them to be picked up by the rest of your application.
☝️ that is, if you're using .NET Core
o
Cheers all. I'll forward this on to those dealing with this 🙂
s
I would check your CSP too, just in case img-src has been set and is stopping them from displaying.
o
good shout on that - I've not got access to the code but will also suggest checking that.
m
Will UrlMode.Absolute also resolve the private url of the webhead according to frontdoor setup? Though if it's frontdoor and multiple webheads, you'll be using blob storage for your images so is there even a need for urlModeAbsolute seen as relative /media will be being mapped to the shared blob storage/cdn? or use a fixed primary host for social platforms?
d
We use Azure Front Door and don't have any issue with absolute URLs, though we only really use them for things like metatags and OG tags etc.
o
Cheers @Dan 'Diplo' Booth - It's really odd.
36 Views