首页 > 开发 > 综合 > 正文

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

2024-07-21 02:28:46
字体:
来源:转载
供稿:网友


数据库采用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);
    }
  }
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表