数据库采用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;
public partial class header_cs : system.web.ui.masterpage {
protected void page_load(object sender, eventargs e) {
sds.selectparameters.add("url",
request.apprelativecurrentexecutionfilepath);
idatareader reader =
(idatareader)sds.select(new datasourceselectarguments());
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);
}
}
}
新闻热点
疑难解答