ASP.net render meta tag validly

后端 未结 2 1383
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 16:57

HTML:


Codebehind:

MetaDescription.Attr         


        
相关标签:
2条回答
  • 2021-01-21 17:57

    I am still on .net 3.5 but put this in Page_Load and it will do what you need:

    HtmlMeta keywords = new HtmlMeta();
    keywords.Name = "keywords";
    keywords.Content = "one two trhee;
    Header.Controls.Add(keywords);
    

    PS: the example is for the keywords tag but the result is the same.

    0 讨论(0)
  • 2021-01-21 18:01

    You should remove the id property from the <meta>, this means the control won't be accessible from the server side by id but instead of it it could be dynamically created and then added to the page:

    HtmlMeta meta = new HtmlMeta();
    meta.Name = "keywords";
    meta.Content = ThisBlog.MetaDescription;
    this.Header.Controls.Add(meta);
    
    0 讨论(0)
提交回复
热议问题