服務(wù)熱線
153 8323 9821
最新發(fā)現(xiàn)方法:在服務(wù)器代碼中寫如下代碼 :
HtmlMeta meta = new HtmlMeta()
meta.Name = "description";
meta.Content = mydr["s_title"].ToString() ;
this.Page.Header.Controls.Add(meta);
以前我用的方法
方法一:
<meta name="keywords" content=<%= keywords %> />
<meta name="description" content=<%=description %> />
注意content 后不要加雙引號喲
后臺中進(jìn)行賦值
string keywords;
string description; void Page_Load(object sender, EventArgs e)
{
keywords = " +mydr["s_title"].ToString() + System.Configuration.ConfigurationSettings.AppSettings["keywords"] + " ;
description = " + mydr["s_title"].ToString() + " ;
}
方法二:
在aspx文件相應(yīng)位置放上<asp:Literal id="keyword" runat="server"></asp:Literal>
cs文件中的代碼為:
this.title=mydr["s_title"].ToString() ;
this.keyword.Text = "<meta name= Keywords content= " + mydr["s_title"].ToString() + " /><meta name= Description content= " + mydr["s_title"].ToString() + " /> ";
這樣就可以做到動態(tài)設(shè)置title,keyword,Descripton了,
相關(guān)知識 ASP:Literal控件用法:剛開始學(xué).NET的朋友可能不清楚Literal和Label到底有什么區(qū)別,其實它們也只有一個區(qū)別,就是在轉(zhuǎn)換成客 戶端Html代碼后,Label就成了<span></span>,而Literal則是什么標(biāo)記都不帶