コード例 #1
0
        /// <summary>
        /// 读取并缓存规则列表
        /// </summary>
        /// <returns></returns>
        protected ArrayList GetRuleList()
        {
            string cacheKey = ConfigHelper.SitePrefix + "rewriterulelist";

            ArrayList ruleList = (ArrayList)HttpContext.Current.Cache.Get(cacheKey);

            if (ruleList == null)
            {
                ruleList = new ArrayList();
                string urlFilePath         = HttpContext.Current.Server.MapPath(string.Format("{0}common/config/rewrite.config", ConfigHelper.SitePath));
                System.Xml.XmlDocument xml = new System.Xml.XmlDocument();

                xml.Load(urlFilePath);

                XmlNode root = xml.SelectSingleNode("rewrite");
                foreach (XmlNode n in root.ChildNodes)
                {
                    if (n.NodeType != XmlNodeType.Comment && n.Name.ToLower() == "item")
                    {
                        RewriterRule rule = new RewriterRule();
                        rule.LookFor = ConfigHelper.SitePath + n.Attributes["lookfor"].Value;
                        rule.SendTo  = ConfigHelper.SitePath + n.Attributes["sendto"].Value;
                        ruleList.Add(rule);
                    }
                }
                HttpContext.Current.Cache.Insert(cacheKey, ruleList, new System.Web.Caching.CacheDependency(urlFilePath));
            }
            return(ruleList);
        }
コード例 #2
0
ファイル: UrlRewriter.cs プロジェクト: robotbird/jqpress
        /// <summary>
        /// 读取并缓存规则列表
        /// </summary>
        /// <returns></returns>
        protected ArrayList GetRuleList()
        {
            string cacheKey = ConfigHelper.SitePrefix + "rewriterulelist";

            ArrayList ruleList = (ArrayList)HttpContext.Current.Cache.Get(cacheKey);
            if (ruleList == null)
            {
                ruleList = new ArrayList();
                string urlFilePath = HttpContext.Current.Server.MapPath(string.Format("{0}common/config/rewrite.config", ConfigHelper.SitePath));
                System.Xml.XmlDocument xml = new System.Xml.XmlDocument();

                xml.Load(urlFilePath);

                XmlNode root = xml.SelectSingleNode("rewrite");
                foreach (XmlNode n in root.ChildNodes)
                {
                    if (n.NodeType != XmlNodeType.Comment && n.Name.ToLower() == "item")
                    {
                        RewriterRule rule = new RewriterRule();
                        rule.LookFor = ConfigHelper.SitePath + n.Attributes["lookfor"].Value;
                        rule.SendTo = ConfigHelper.SitePath + n.Attributes["sendto"].Value;
                        ruleList.Add(rule);
                    }
                }
                HttpContext.Current.Cache.Insert(cacheKey, ruleList, new System.Web.Caching.CacheDependency(urlFilePath));
            }
            return ruleList;
        }