一、.net 3.5下
1、母版頁前臺
<title><%=title %></title>
<meta name="description" content=<%=description %> />
<meta name="keywords" content=<%=keywords %> />
2、母版頁后臺
public string title="網(wǎng)站默認(rèn)標(biāo)題";
public string description="網(wǎng)站默認(rèn)描述";
public string keywords="網(wǎng)站默認(rèn)關(guān)鍵詞";
3、內(nèi)容頁后臺
(this.Master as TopDown).title = "內(nèi)容頁標(biāo)題"; //注: TopDown 為母版頁的名稱
(this.Master as TopDown ).description = "內(nèi)容頁描述";
(this.Master as TopDown ).keywords = "內(nèi)容頁關(guān)鍵詞";
二、.net 4.0下
1、母版頁前臺
<title> 網(wǎng)站默認(rèn)標(biāo)題 </title>
<meta runat="server" name="description" content="網(wǎng)站默認(rèn)描述" />
<meta runat="server" name="keywords" content="網(wǎng)站默認(rèn)關(guān)鍵詞" />
2、母版頁后臺
3、內(nèi)容頁后臺
this.Title = "內(nèi)容頁標(biāo)題";
this.MetaKeywords = "內(nèi)容頁關(guān)鍵詞";
this.MetaDescription = "內(nèi)容頁描述";
同樣.net 4.0 下也可采用.net 3.5 的方法
HtmlMeta hmKeywords = new HtmlMeta(); //
hmKeywords.Name = "keywords";
hmKeywords.Content = "關(guān)鍵詞";
Page.Header.Controls.Add(hmKeywords); //內(nèi)容頁添加屬性 head.Controls.Add( hmKeywords); //母版頁添加屬性
HtmlMeta hmDescription = new HtmlMeta();
hmDescription.Name = "description";
hmDescription.Content = "描述";
Page.Header.Controls.Add(hmDescription);