简体   繁体   中英

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. Inferred Property: The 'og:title' property should be explicitly provided, even if a value can be inferred from other tags. Inferred Property: The 'og:description' property should be explicitly provided, even if a value can be inferred from other tags. Inferred Property: The 'og:image' property should be explicitly provided, even if a value can be inferred from other tags.

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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