124

I'm adding Facebook Open Graph meta tag to my site. For example:

<meta property="og:image" content="../images/aa.jpg"/>

Does Open Graph take relative URLs?

Otherwise, how can I convert a relative url to an absolute url in asp.net mvc3 - Is there any available function to do so?

Ethan
  • 3,410
  • 1
  • 28
  • 49
ebattulga
  • 10,774
  • 20
  • 78
  • 116

3 Answers3

127

Documentation have nothing about it, but relative URLs will not work, only full URL including scheme works.

As long as only full URLs supported you may convert relative to absolute url using URL.Content method (as suggested in What is the equivalent to Page.ResolveUrl in ASP.NET MVC?)

NOTES:

A string of Unicode characters forming a valid URL having the http or https scheme.

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
2

I set up an og:image tag on my website with a relative url, and even though facebook reports an error like this :

Object at URL 'http://***/' of type 'website' is invalid because the given value 'preview.png' for property 'og:image:url' could not be parsed as type 'url'.

on https://developers.facebook.com/tools/debug/og/object/, the image shows up in the preview.

So I guess this is kind of supported, at least on facebook.

Zonko
  • 3,365
  • 3
  • 20
  • 29
  • 17
    it might looks like it works because of the fallback to the best/first image found on the site – Felipe Pereira Feb 24 '17 at 00:12
  • 1
    It probably "seems" to work because: "Without these Open Graph tags, the Facebook Crawler uses internal heuristics to make a best guess about the title, description, and preview image for your content." -source: https://developers.facebook.com/docs/sharing/webmasters/ So, yes, probably FB is using its own fallback mechanism in this case, when it fails to parse the image URL. – Gerard Bosch Sep 23 '21 at 14:34
-1

If you are setting the value of the og:url meta node from within a Controller Action you can use:

Request.Url.AbsoluteUri()

Chris
  • 3,210
  • 1
  • 33
  • 35