ASP.NET2.0新增的功能,由於經常采用一個頁面通過不同的參數來顯示不同的內容,因此常常需要實現動態輸出不同的htmlheader, 比如title, keywords, descrtptions,csslink,meta,icon等。代碼如下:
protected void Page_Load(object sender, EventArgs e) { //Page title Page.Title ="標題"; //Encode/Content type HtmlMeta encode = new HtmlMeta(); encode.HttpEquiv ="Content-Type"; encode.C; Page.Header.Controls.Add(encode); //Language HtmlMeta lang = new HtmlMeta(); lang.HttpEquiv ="Content-Language"; lang.C; Page.Header.Controls.Add(lang); //Description HtmlMeta desc = new HtmlMeta(); desc.Name ="Description"; desc.C; Page.Header.Controls.Add(desc); //Keyword HtmlMeta keywords = new HtmlMeta(); keywords.Name ="keywords"; keywords.Content = "ASP.net,數據訪問,ASP.net控件,AJAX ,ADO.net,WebServer"; Page.Header.Controls.Add(keywords); //Link/CSS HtmlLink cssLink = new HtmlLink(); cssLink.Href ="鏈接地址"; cssLink.Attributes.Add("rel", "stylesheet"); cssLink.Attributes.Add("type", "text/css"); Page.Header.Controls.Add(cssLink); //Link/ico HtmlLink icoLink = new HtmlLink(); icoLink.Href ="/favicon.ico"; icoLink.Attributes.Add("rel", "shortcut icon"); Page.Header.Controls.Add(icoLink); }