今天做項(xiàng)目,遇到了兩個(gè)問題。1.如何讀取 meta標(biāo)簽屬性,知道如何寫入,HtmlMeta keywords = new HtmlMeta();HtmlMeta description = new HtmlMeta();keywords.Name = "keywords";description.Name = "description";keywords.Content = txtkeywords.Text.Trim();description.Content = txtdis.Value.Trim();this.Page.Header.Controls.Add(keywords);this.Page.Header.Controls.Add(description);以為這樣能讀取,string readkey=keywords.Content.Tostring();結(jié)果不能,這第一個(gè)問題就是如何讀取meta下標(biāo)簽的內(nèi)容。2,我們用的.net開發(fā)一般都是用模板頁,怎么給不同的頁面動(dòng)態(tài)設(shè)置meta標(biāo)簽屬性呢?
2 回答

米琪卡哇伊
TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊
1. this.Page.Header.FindControl("meta控件ID") as HtmlMeta
2. Master.Page.Header.FindControl("meta控件ID") as HtmlMeta

HUX布斯
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
舉個(gè)列
<head runat="server">
<title></title>
<meta name="keywords" content="aa">
<meta name="description" content="bb">
</head>
加載事件:
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(Page.MetaDescription);
Response.Write(Page.MetaKeywords);
}
- 2 回答
- 0 關(guān)注
- 630 瀏覽
添加回答
舉報(bào)
0/150
提交
取消