I know this has to be a duplicate, but I've been wading through the hordes of information on this and I can't get it work.
I'm trying to get a site working on a client's server and they have the site installed in a virtual directory. I don't have this setup, locally, so I'm flying blind here.
I'm trying to build a path to an image. (it's for Facebook OpenGraph Meta data).
I need the path to the image to be a fully-qualified, absolute url. I've tried so many things, but nothing seems to work. The code below outputs a relative url, but this will not work.
<% var urlHelper = VirtualPathUtility.ToAbsolute("~/static/images/image.jpg");%>
<meta property="og:image" content="<%=urlHelper%>" />
outputs:
<meta property="og:image" content="/static/images/image.jpg" />
I've also tried:
<% var serverHost = HttpContext.Current.Request.Url; %>
<meta property="og:image"
content="<%=serverHost + "/static/images/image.jpg"%>" />
But that's producing:
<meta property="og:image"
content="http://localhost:51863/ViewFile.aspx/static/images/image.jpg" />
I'm looking for http://example.com/virtualdirectory/static/images/image.jpg
Any help will be much appreciated. I really don't want to have to hard-code the url.
Thanks, Scott
EDIT
I neglected to mention that my very first attempt was Url.Content("~/....jpg) but that outputs a relative url, not an abosolute one.