Html 打开图可以解析相对url吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9858577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 23:20:16  来源:igfitidea点击:

Open graph can resolve relative url?

htmlfacebook-opengraphmeta-tagsmeta

提问by ebattulga

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

我正在向我的网站添加 Facebook Open Graph 元标记。例如:

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

Does Open Graph take relative URLs?

Open Graph 是否采用相对 URL?

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

否则,我怎么能转换成一个相对URL到一个绝对的URLasp.net MVC3-是否有任何可用的功能,这样做呢?

采纳答案by Juicy Scripter

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

文档对此一无所知,但相对 URL 不起作用,只有包含方案的完整 URL 才有效。

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

只要只支持完整的 URL,您就可以使用URL.Content方法相对于绝对 url 进行转换(如什么是 ASP.NET MVC 中的 Page.ResolveUrl 等价物?

NOTES:

笔记:

回答by Zonko

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

og:image在我的网站上设置了一个带有相对 url的标签,即使 facebook 报告了这样的错误:

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'.

位于 URL 'http://***/' 的类型为“website”的对象无效,因为无法将属性“og:image:url”的给定值“preview.png”解析为类型“url”。

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

https://developers.facebook.com/tools/debug/og/object/ 上,图像显示在预览中。

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

所以我想这是一种支持,至少在 facebook 上。

回答by Chris

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

如果您og:url从控制器操作中设置元节点的值,您可以使用:

Request.Url.AbsoluteUri()

Request.Url.AbsoluteUri()