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
相关文章读者评论发表评论 |