ASP.NET 如何动态修改 Header 属性如添加 Meta 标签 keywords

 我来答
点点半玩迎04
2013-11-02 · 超过60用户采纳过TA的回答
知道答主
回答量:116
采纳率:33%
帮助的人:112万
展开全部
推荐的简单做法如下:protected void Page_Load(object sender, EventArgs e){ //Page title Page.Title = "This is a title and meta test page."; //Encode/Content type HtmlMeta encode = new HtmlMeta(); encode.HttpEquiv = "Content-Type"; encode.Content = "text/html; charset=utf-8"; Page.Header.Controls.Add(encode); //Language HtmlMeta lang = new HtmlMeta(); lang.HttpEquiv = "Content-Language"; lang.Content = "zh-cn"; Page.Header.Controls.Add(lang); //Description HtmlMeta desc = new HtmlMeta(); desc.Name = "Description"; desc.Content = "Test the meta controls"; Page.Header.Controls.Add(desc); //Keyword HtmlMeta keywords = new HtmlMeta(); keywords.Name = "keywords"; keywords.Content = "title,meta,test,page"; Page.Header.Controls.Add(keywords); //Link/CSS HtmlLink cssLink = new HtmlLink(); cssLink.Href = "MasterPage.css"; cssLink.Attributes.Add("rel", "stylesheet"); cssLink.Attributes.Add("type", "text/css"); Page.Header.Controls.Add(cssLink);}浏览时输出的页面源码便会达到如下效果:This is a title and meta test page. 1024) { keywords.Content = keywords.Content.Substring(0, keywords.Content.IndexOf(" ", 1024)); } description.Content = "This web site use asp.net2.0 and C# and Ajax technology"; if (description.Content.ToString().Length > 1024) { description.Content = description.Content.Substring(0, description.Content.IndexOf(" ", 1024)); } htmlCtrl.Controls.Add(author); htmlCtrl.Controls.Add(copyright); htmlCtrl.Controls.Add(date); htmlCtrl.Controls.Add(keywords); htmlCtrl.Controls.Add(description); htmlCtrl.Controls.Add(robots); } #endregion PAGE HEAD
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式