当前位置:首页 > 页面根据不同Url显示不同Title以及不同的Mete

页面根据不同Url显示不同Title以及不同的Mete

点击次数:1365  更新日期:2010-12-25
\n

数据库采用SQL Server 2005 Express Edition, 数据库构造就不说了。
SQL语句: SELECT title, keywords, description FROM PageInfo WHERE (url= @url)SqlDataSource,名字为sds
具体的代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


\n

public partial class Header_cs : System.Web.UI.MasterPage {
protected void Page_Load(object sender, EventArgs e) {


\n

sds.SelectParameters.Add(“url”,
Request.AppRelativeCurrentExecutionFilePath);
IDataReader reader =
(IDataReader)sds.Select(new DataSourceSelectArguments());


\n

if (reader.Read()) {
Page.Header.Title = reader.GetString(0);
HtmlMeta meta1 = new HtmlMeta();
HtmlMeta meta2 = new HtmlMeta();
meta1.Name = “keywords”;
meta1.Content = reader.GetString(1);
meta2.Name = “description”;
meta2.Content = reader.GetString(2);
Page.Header.Controls.Add(meta1);
Page.Header.Controls.Add(meta2);
}
}
}


\n

来源:网络

\n