httpModule 伪静态

C# code

   
public class HttpModule : System.Web.IHttpModule { /// <summary> /// 实现接口的Init方法 /// </summary> /// <param name="context"></param> public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(ReUrl_BeginRequest); } public void Application_OnError(Object sender, EventArgs e) { } /// <summary> /// 实现接口的Dispose方法 /// </summary> public void Dispose() { } /// <summary> /// 重写Url /// </summary> /// <param name="sender"> 事件的源 </param> /// <param name="e"> 包含事件数据的 EventArgs </param> private void ReUrl_BeginRequest( object sender, EventArgs e) { // --------------------- // // string templateid = "1"; // --------------------- // HttpContext context = ((HttpApplication)sender).Context; Ccdodo.Entity.ConfigInfo Config = Ccdodo.XmlLib.XmlData.Config; // string SitePath = config.SitePath; string requestPath = context.Request.Path.ToLower(); // string path = requestPath.Substring(Config.SitePath.Length + 5); // if (requestPath.StartsWith(Config.SitePath + " bbs " ) || requestPath.StartsWith(Config.SitePath + " /bbs " )) { context.RewritePath(Config.SitePath + requestPath); // System.Web.HttpContext.Current.Response.Write(requestPath + ":" + Config.SitePath + requestPath + ":" + requestPath.StartsWith(Config.SitePath + "bbs/")); // System.Web.HttpContext.Current.Response.End(); } else { foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls) { // System.Web.HttpContext.Current.Response.Write(Regex.IsMatch(path, url.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).ToString() + "<br/>"); // System.Web.HttpContext.Current.Response.Write(Config.SitePath + url.Page + "<br/>" + newUrl + "<br/><br/>" + requestPath + "<br/>" + url.Pattern); if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase)) { // 实际地址 string newUrl = Regex.Replace(context.Request.Path, url.Pattern, url.QueryString, RegexOptions.Compiled | RegexOptions.IgnoreCase); // System.Web.HttpContext.Current.Response.Write(Regex.IsMatch(requestPath, url.Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase).ToString() + "<br/>"); // System.Web.HttpContext.Current.Response.Write(Config.SitePath + url.Page + "<br/>" + newUrl + "<br/><br/>" + requestPath + "<br/>" + url.Pattern); // System.Web.HttpContext.Current.Response.End(); context.RewritePath(Config.SitePath + url.Page, string .Empty, newUrl); return ; } // } } context.RewritePath(Config.SitePath + requestPath); // -- // } }

你可能感兴趣的:(Module)