Is it possible to get the absolute URL of an image in razor? I'm trying to use the following, simply putting http://www.mysite.com in front of it doesn't work...
Hi Douglas, I'm getting the following error with the second method you recommend: 'string' does not contain a definition for 'umbracoFile'
And with the first, if I just add http://mysite.com before it, it pritns the actual code for some reason instead of the path to the image, it prints the image path fine without the prepended url...
Absolute image URL
Hi,
Is it possible to get the absolute URL of an image in razor? I'm trying to use the following, simply putting http://www.mysite.com in front of it doesn't work...
Thanks,
Amir
Umbraco doesn't know what the server binding is as far as I know, but you can get the domain using the HTTPContext.
I'm just curious why hardcoding http://www.mysite.com in front of it doesn't work for you.
That should work just fine. But using the HTTPContext:
...you can get to it that way. But HTTPContext allows you to access your site's url dynamically.
Hi Douglas, I'm getting the following error with the second method you recommend: 'string' does not contain a definition for 'umbracoFile'
And with the first, if I just add http://mysite.com before it, it pritns the actual code for some reason instead of the path to the image, it prints the image path fine without the prepended url...
Any ideas?
Thanks!
Amir
Sorry, method 1 was untested. The way to fix that is to wrap parentheses around the razor code like so:
<span class='st_pinterest' st_img="http://www.mysite.com@(Model.Media("headerImage", "umbracoFile"))" displayText='Share'></span>
Using method 2, make sure you're using the dynamic keyword
First one works great! Thanks douglas. Glad to learn that method in general, I'm sure I'll use it again.
Hello from 2018 :)
More obvios way:
I came across this tonight while trying to resolve an issue in Umbraco 8.x, the below code worked in my use case.
is working on a reply...