转自:http://www.cnblogs.com/andyliu/archive/2006/03/28/360645.html
收集一些偶然看到的小Tips,先列一些在这儿,慢慢补充。
设置Title :
this.Header.Title="这是个Title测试";
如果用了MasterPage可以这样用:
this.Page.Title = SiteMap.CurrentNode.Title;
动态设置Style:
Style style = new Style();
style.ForeColor = System.Drawing.Color.Navy;
style.BackColor = System.Drawing.Color.LightGray;
// Add the style to the header for the body of the page
this.Header.StyleSheet.CreateStyleRule(style, null, "body");
动态加样式表:
HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/newstyle.css");
this.Header.Controls.Add(link);
动态加meta tags :
//Encode/Content type
HtmlMeta encode = new HtmlMeta();
encode.HttpEquiv = "Content-Type";
encode.Content = "text/html; charset=utf-8";
Page.Header.Controls.Add(encode);
//Language
HtmlMeta lang = new HtmlMeta();
lang.HttpEquiv = "Content-Language";
lang.Content = "zh-cn";
Page.Header.Controls.Add(lang);
//Description
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = "Test the meta controls";
Page.Header.Controls.Add(desc);
//Keyword
HtmlMeta keywords = new HtmlMeta();
keywords.Name = "keywords";
keywords.Content = "title,meta,test,page";
Page.Header.Controls.Add(keywords);
//refresh
HtmlMeta refresh = new HtmlMeta();
refresh.HttpEquiv = "Refresh";
refresh.Content = "3; url=http://www.baidu.com.cn";
Page.Header.Controls.Add(refresh);
ASP.NET页面动态配置技巧
本文介绍了在ASP.NET中如何动态地为页面设置标题、样式、样式表及元标签等,通过实例展示了如何利用C#代码实现这些配置,有助于提高网站的SEO效果和用户体验。

被折叠的 条评论
为什么被折叠?



