ASP.NET动态修改浏览器title,keywords,descrtptions,csslink,meta,icon等
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.C;
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);
}