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);
精彩评论