日期:2014-05-18 浏览次数:20493 次
// Render: <meta name="keywords" content="Some words listed here" /> HtmlMeta meta = new HtmlMeta(); meta.Name = "keywords"; meta.Content = "Some words listed here"; this.Header.Controls.Add(meta); // Render: <meta name="robots" content="noindex" /> meta = new HtmlMeta(); meta.Name = "robots"; meta.Content = "noindex"; this.Header.Controls.Add(meta); // Render: <meta name="date" content="2006-03-25" scheme="YYYY-MM-DD" /> meta = new HtmlMeta(); meta.Name = "date"; meta.Content = DateTime.Now.ToString("yyyy-MM-dd"); meta.Scheme = "YYYY-MM-DD"; this.Header.Controls.Add(meta);
------解决方案--------------------
我是写在masterpage里,不同的页,赋值Session("currentpage"),根据库里的不同页不同关键词填充。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
makemeta(Session("currentpage"))
End Sub
Sub makemeta(ByVal item As String)
Dim ds As DataSet = toolClass.getmeta(item)
Page.Title = ds.Tables(0).Rows(0)("title")
Dim meta As New HtmlMeta
meta.Name = "keywords"
meta.Content = ds.Tables(0).Rows(0)("keywords")
Page.Header.Controls.Add(meta)
meta.Name = "description"
meta.Content = ds.Tables(0).Rows(0)("description")
Page.Header.Controls.Add(meta)
End Sub
------解决方案--------------------
public class initfunc : System.Web.UI.Page { public initfunc() { // // TODO: 在此处添加构造函数逻辑 // } public void setMeta(System.Web.UI.Control page,string key, string des) { HtmlMeta keywords = new HtmlMeta(), description = new HtmlMeta(); // keywords, description keywords.Name = "keywords"; keywords.Content = key; description.Name = "description"; description.Content = des; page.Header.Controls.Add(keywords); page.Header.Controls.Add(description); } } //加个参数,使用的时候 initfunc ini = new initfunc(); protected void Page_Load(object sender, EventArgs e) { ini.setMeta(this,"1111", "2222"); }
------解决方案--------------------
public class AA { public static void setMeta(string keyWords) { System.Web.UI.HtmlControls.HtmlMeta m = new HtmlMeta(); m.Name = "keywords"; m.Content =