简体   繁体   English

Facebook喜欢按钮OG标签

[英]Facebook like button OG-tags

I have a method like this: 我有这样的方法:

private void LoadMetaTagsForFacebook()
{
    HtmlMeta meta = new HtmlMeta();
    meta.Attributes.Add("property", "fb:app_id");
    meta.Attributes.Add("content", "");
    Page.Header.Controls.Add(meta);

    meta = new HtmlMeta();
    meta.Attributes.Add("property", "og:url");
    meta.Attributes.Add("content", Request.Url.ToString());
    Page.Header.Controls.Add(meta);

    meta = new HtmlMeta();
    meta.Attributes.Add("property", "og:site_name");
    meta.Attributes.Add("content", "Site.com");
    Page.Header.Controls.Add(meta);

    meta = new HtmlMeta();
    meta.Attributes.Add("property", "og:title");
    meta.Attributes.Add("content", this._product.Name);
    Page.Header.Controls.Add(meta);

    meta = new HtmlMeta();
    meta.Attributes.Add("property", "og:image");
    meta.Attributes.Add("content", this._product.ImagePath);
    Page.Header.Controls.Add(meta);

    meta = new HtmlMeta();
    meta.Attributes.Add("property", "og:type");
    meta.Attributes.Add("content", "drink");
    Page.Header.Controls.Add(meta);
}

But when i run the debugger i get this error: 但是,当我运行调试器时,出现此错误:

Inferred Property: The 'og:url' property should be explicitly provided, even if a value can be inferred from other tags. 推断属性:即使可以从其他标签推断值,也应明确提供'og:url'属性。 Inferred Property: The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags. 推断属性:即使可以从其他标签推断值,也应明确提供'og:title'属性。 Inferred Property: The 'og:description' property should be explicitly provided, even if a value can be inferred from other tags. 推断属性:即使可以从其他标签推断值,也应明确提供'og:description'属性。 Inferred Property: The 'og:image' property should be explicitly provided, even if a value can be inferred from other tags. 推断的属性:即使可以从其他标签推断值,也应明确提供'og:image'属性。

  1. When i look at the page source on the site the meta tags is right.. do i have to add the meta tags in a other way? 当我在网站上查看页面源代码时,meta标签是正确的..我是否必须以其他方式添加meta标签? How do i do that? 我怎么做?

  2. I also get a error because i have a redirect path (you have to be logged in to see the page). 我也收到一条错误消息,因为我有一个重定向路径(您必须登录才能查看页面)。 What´s the solution for this? 解决方案是什么?

I would be very happy for an answear and i accept the answears if the help me.. i have spent 3 hours searching and trying. 我会对answear感到非常高兴,如果可以帮助我,我会接受answears。.我花了3个小时进行搜索和尝试。

Thanks alot! 非常感谢!

Try using "Name" instead of "Property", I made a test here and it works. 尝试使用“名称”代替“属性”,我在这里进行了测试,它可以正常工作。

        meta= new HtmlMeta();
        meta.Attributes.Add("name", "og:title");
        meta.Content = this._product.Name;
        Page.Header.Controls.Add(meta);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM