/// <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;
            string      ext         = requestPath.GetExtension().ToLower();

            if (ext != RewriterConfiguration.RewriteExt)
            {
                return;
            }

            string matchUrl  = RewriterHelper.ResolveUrl(context.Request.ApplicationPath, requestPath);
            string actionUrl = matchUrl.ChangeExtension(".aspx");

            //("1|" + matchUrl + "|" + actionUrl).ToFile("e:\\log.txt", Encoding.UTF8, false);
            RewriterHelper.RewriteUrl(context, actionUrl);
        }
Beispiel #2
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;
                }
            }
        }