httpModule 偽靜態

來源:互聯網
上載者:User
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);//--//        }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.