开发者

ASP.NET Metatag element

Im trying to add metatag programatically to my page in asp.net using:

HtmlMeta meta = new HtmlMeta();
meta.Name = "keywords";
meta.Content = "test,test1";
this.Master.Page.Header.Controls.Add(meta);

but the Master.Page.Header is always NULL.

Any i开发者_开发问答deias?


The <head> element of your master page must have the runat="server" attribute. If it doesn't, Page.Header will always be null.


Try this:

HtmlHead head = this.Master.Page.Header;
HtmlMeta meta = new HtmlMeta();
meta.Name = "Description";
meta.Content = "Friendly and relevant content";
head.Controls.Add(meta); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜