asp.net动态设置标题title 关键字keywords 描述descrtptions
Posted on 2015-09-17 17:45 股墓山庄庄主 阅读(221) 评论(0) 编辑 收藏 举报推荐的简单做法如下:
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);
}