using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> ///UrlRewriter 的摘要说明 /// </summary> public class UrlRewriter:IHttpModule { public UrlRewriter() { // //TODO: 在此处添加构造函数逻辑 // } #region IHttpModule 成员 public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); ; } void context_BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; string requestPath = context.Request.Path.ToLower(); //判断请求路径是否为鲜花页面 if (requestPath.Contains("/webhttpmodule/flower/")) { //找到路径中最后一个"/"的位置 int start = requestPath.LastIndexOf("/"); //找到最后一个"."的位置 int end = requestPath.LastIndexOf("."); string id = requestPath.Substring(start + 1, (end - start)); context.RewritePath("~/flower/flower.aspx?id=" + id); } } #endregion }