Beispiel #1
0
        /// <summary>
        /// 重写Url
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RewriterUrl_BeginRequest(object sender, EventArgs e)
        {
            HttpContext   context     = ((HttpApplication)sender).Context;
            string        requestPath = context.Request.Path;
            RewriterRules rules       = RewriterConfiguration.GetConfig().Rules;

            for (int i = 0; i < rules.Count; i++)
            {
                string matchUrl = "^" + RewriterHelper.ResolveUrl(context.Request.ApplicationPath, rules[i].Match) + "$";
                Regex  re       = new Regex(matchUrl, RegexOptions.IgnoreCase);
                //matchUrl.ToFile("~/log.txt".GetMapPath(), Encoding.UTF8, false);
                if (re.IsMatch(requestPath))
                {
                    string actionUrl = RewriterHelper.ResolveUrl(context.Request.ApplicationPath, re.Replace(requestPath, rules[i].Action));
                    //actionUrl.ToFile("~/log.txt".GetMapPath(), Encoding.UTF8, false);
                    RewriterHelper.RewriteUrl(context, actionUrl);
                    break;
                }
            }
        }
        /// <summary>
        /// 重写Url
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RewriterUrl_BeginRequest(object sender, EventArgs e)
        {
            HttpContext   context     = ((HttpApplication)sender).Context;
            string        requestPath = context.Request.Path;
            RewriterRules rules       = CMSURLData.Rules;

            //("0|" + rules.Count).ToFile("e:\\log.txt", Encoding.UTF8, false);
            for (int i = 0; i < rules.Count; i++)
            {
                string matchUrl = "^" + RewriterHelper.ResolveUrl(context.Request.ApplicationPath, rules[i].Match) + "$";
                Regex  re       = new Regex(matchUrl, RegexOptions.IgnoreCase);
                //("1|" + matchUrl + "|" + requestPath).ToFile("e:\\log.txt", Encoding.UTF8, false);
                if (re.IsMatch(requestPath))
                {
                    string actionUrl = RewriterHelper.ResolveUrl(context.Request.ApplicationPath, re.Replace(requestPath, rules[i].Action));
                    //("2|" + actionUrl).ToFile("e:\\log.txt", Encoding.UTF8, false);
                    RewriterHelper.RewriteUrl(context, actionUrl);
                    break;
                }
            }
        }