ASP.net渲染meta标签有效 [英] ASP.net render meta tag validly
本文介绍了ASP.net渲染meta标签有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML
<meta name="description" runat="server" id="MetaDescription" content="" />
codebehind:
Codebehind:
MetaDescription.Attributes["content"] = ThisBlog.MetaDescription;
这将呈现为:
<meta id="HeadContent_MetaDescription" name="description" content="My page description"></meta>
作为每个<一href=\"http://webmasters.stackexchange.com/questions/10237/redundant-meta-attributes/10238#10238\">this回答它需要没有ID属性,并关闭与 /方式&gt;
As per this answer it needs to have no ID attribute, and close with />
.
怎样才能使它以这种方式呈现?
How can I make it render in this way?
推荐答案
我仍然在.NET 3.5,但把这个在Page_Load中,它会做你需要什么:
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:这个例子是关键词标签,但结果是一样的。
PS: the example is for the keywords tag but the result is the same.
这篇关于ASP.net渲染meta标签有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文