专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »DotNet » url重写代码:RewritePath() 实现简单高效的URL重写代码 »正文

url重写代码:RewritePath() 实现简单高效的URL重写代码

来源: 发布时间:星期四, 2009年2月12日 浏览:437次 评论:0


//原始URL:http://www.ccol.cn/s/12/66.aspx
//转换后URL:http://www.ccol.cn/s.aspx?q1=12&q2=66

protected void Application_BeginRequest(Object sender, EventArgs e)
{
Regex re = Regex(@"^((/[^/0-9]+)+)(/[0-9]+(/[^/]+)*)\.aspx$", RegexOptions.Compiled);
Match match = re.Match(HttpContext.Current.Request.Path);

(match.Success)
{
re = Regex(@"/([^/]+)", RegexOptions.Compiled);
MatchCollection matches = re.Matches(match.Result("$3"));

page = match.Result("$1")+".aspx?q0="+matches[0].Result("$1");
for( i=1; i<matches.Count; i)
{
page "&q"+i+"="+matches[i].Result("$1");
}

HttpContext.Current.RewritePath(page); //关键步骤
}
}
1

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: