Пример #1
0
        /// <summary>
        /// 参数个数是否匹配
        /// </summary>
        private bool IsUrlMatch(Model.url_rewrite_item item, params object[] _params)
        {
            int strLength = 0;

            if (!string.IsNullOrEmpty(item.querystring))
            {
                strLength = item.querystring.Split('&').Length;
            }
            if (strLength == _params.Length)
            {
                //注意__id__代表分页页码,所以须替换成数字才成进行匹配
                if (Regex.IsMatch(string.Format(item.path, _params).Replace("__id__", "1"), item.pattern, RegexOptions.None | RegexOptions.IgnoreCase))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// 返回URL重写统一链接地址(2017-08-14)
        /// </summary>
        public string linkurl(Model.url_rewrite model, params object[] _params)
        {
            string requestDomain   = System.Web.HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号
            string requestPath     = System.Web.HttpContext.Current.Request.RawUrl.ToLower();        //当前的URL地址
            string linkStartString = GetLinkStartString(requestPath, requestDomain);                 //链接前缀

            //如果URL字典表达式不需要重写则直接返回
            if (model.url_rewrite_items.Count == 0)
            {
                //检查网站重写状态
                if (config.staticstatus > 0)
                {
                    if (_params.Length > 0)
                    {
                        return(linkStartString + GetUrlExtension(model.page, config.staticextension) + string.Format("{0}", _params));
                    }
                    else
                    {
                        return(linkStartString + GetUrlExtension(model.page, config.staticextension));
                    }
                }
                else
                {
                    if (_params.Length > 0)
                    {
                        return(linkStartString + model.page + string.Format("{0}", _params));
                    }
                    else
                    {
                        return(linkStartString + model.page);
                    }
                }
            }
            if (model.url_rewrite_items.Count == 1 && _params.Length > 0)
            {
                Model.url_rewrite_item item = model.url_rewrite_items[0];
                if (string.IsNullOrEmpty(item.querystring))
                {
                    //检查网站重写状态
                    if (config.staticstatus > 0)
                    {
                        return(linkStartString + GetUrlExtension(item.path, config.staticextension) + string.Format("{0}", _params));
                    }
                    else
                    {
                        return(linkStartString + item.path + string.Format("{0}", _params));
                    }
                }
            }
            //否则检查该URL配置节点下的子节点
            foreach (Model.url_rewrite_item item in model.url_rewrite_items)
            {
                //如果参数个数匹配
                if (IsUrlMatch(item, _params))
                {
                    //检查网站重写状态
                    if (config.staticstatus > 0)
                    {
                        return(linkStartString + string.Format(GetUrlExtension(item.path, config.staticextension), _params));
                    }
                    else
                    {
                        string queryString = Regex.Replace(string.Format(item.path, _params), item.pattern, item.querystring, RegexOptions.None | RegexOptions.IgnoreCase);
                        if (queryString.Length > 0)
                        {
                            queryString = "?" + queryString;
                        }
                        return(linkStartString + model.page + queryString);
                    }
                }
            }

            return(string.Empty);
        }
Пример #3
0
        /// <summary>
        /// 取得URL配制列表
        /// </summary>
        public List <Model.url_rewrite> GetList(string channel)
        {
            List <Model.url_rewrite> ls = new List <Model.url_rewrite>();
            string      filePath        = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
            XmlDocument doc             = new XmlDocument();

            doc.Load(filePath);
            XmlNode xn = doc.SelectSingleNode("urls");

            foreach (XmlElement xe in xn.ChildNodes)
            {
                if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite")
                {
                    if (xe.Attributes["name"] != null)
                    {
                        if (!string.IsNullOrEmpty(channel))
                        {
                            if (xe.Attributes["channel"] != null && channel.ToLower() == xe.Attributes["channel"].Value.ToLower())
                            {
                                Model.url_rewrite model = new Model.url_rewrite();
                                if (xe.Attributes["name"] != null)
                                {
                                    model.name = xe.Attributes["name"].Value;
                                }
                                if (xe.Attributes["type"] != null)
                                {
                                    model.type = xe.Attributes["type"].Value;
                                }
                                if (xe.Attributes["page"] != null)
                                {
                                    model.page = xe.Attributes["page"].Value;
                                }
                                if (xe.Attributes["inherit"] != null)
                                {
                                    model.inherit = xe.Attributes["inherit"].Value;
                                }
                                if (xe.Attributes["templet"] != null)
                                {
                                    model.templet = xe.Attributes["templet"].Value;
                                }
                                if (xe.Attributes["channel"] != null)
                                {
                                    model.channel = xe.Attributes["channel"].Value;
                                }
                                if (xe.Attributes["pagesize"] != null)
                                {
                                    model.pagesize = xe.Attributes["pagesize"].Value;
                                }
                                //再次遍历子节点
                                StringBuilder urlRewriteString        = new StringBuilder();
                                List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>();
                                foreach (XmlElement xe1 in xe.ChildNodes)
                                {
                                    if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                    {
                                        Model.url_rewrite_item item = new Model.url_rewrite_item();
                                        if (xe1.Attributes["path"] != null)
                                        {
                                            item.path = xe1.Attributes["path"].Value;
                                        }
                                        if (xe1.Attributes["pattern"] != null)
                                        {
                                            item.pattern = xe1.Attributes["pattern"].Value;
                                        }
                                        if (xe1.Attributes["querystring"] != null)
                                        {
                                            item.querystring = xe1.Attributes["querystring"].Value;
                                        }
                                        urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                                        lsItems.Add(item);
                                    }
                                }
                                model.url_rewrite_str   = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                                model.url_rewrite_items = lsItems;
                                ls.Add(model);
                            }
                        }
                        else
                        {
                            Model.url_rewrite model = new Model.url_rewrite();
                            if (xe.Attributes["name"] != null)
                            {
                                model.name = xe.Attributes["name"].Value;
                            }
                            if (xe.Attributes["type"] != null)
                            {
                                model.type = xe.Attributes["type"].Value;
                            }
                            if (xe.Attributes["page"] != null)
                            {
                                model.page = xe.Attributes["page"].Value;
                            }
                            if (xe.Attributes["inherit"] != null)
                            {
                                model.inherit = xe.Attributes["inherit"].Value;
                            }
                            if (xe.Attributes["templet"] != null)
                            {
                                model.templet = xe.Attributes["templet"].Value;
                            }
                            if (xe.Attributes["channel"] != null)
                            {
                                model.channel = xe.Attributes["channel"].Value;
                            }
                            if (xe.Attributes["pagesize"] != null)
                            {
                                model.pagesize = xe.Attributes["pagesize"].Value;
                            }
                            //再次遍历子节点
                            StringBuilder urlRewriteString        = new StringBuilder();
                            List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>();
                            foreach (XmlElement xe1 in xe.ChildNodes)
                            {
                                if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                {
                                    Model.url_rewrite_item item = new Model.url_rewrite_item();
                                    if (xe1.Attributes["path"] != null)
                                    {
                                        item.path = xe1.Attributes["path"].Value;
                                    }
                                    if (xe1.Attributes["pattern"] != null)
                                    {
                                        item.pattern = xe1.Attributes["pattern"].Value;
                                    }
                                    if (xe1.Attributes["querystring"] != null)
                                    {
                                        item.querystring = xe1.Attributes["querystring"].Value;
                                    }
                                    urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                                    lsItems.Add(item);
                                }
                            }
                            model.url_rewrite_str   = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                            model.url_rewrite_items = lsItems;
                            ls.Add(model);
                        }
                    }
                }
            }
            return(ls);
        }
Пример #4
0
        /// <summary>
        /// 取得节点配制信息
        /// </summary>
        public Model.url_rewrite GetInfo(string attrValue)
        {
            Model.url_rewrite model    = new Model.url_rewrite();
            string            filePath = Utils.GetXmlMapPath(DTKeys.FILE_URL_XML_CONFING);
            XmlDocument       doc      = new XmlDocument();

            doc.Load(filePath);
            XmlNode     xn     = doc.SelectSingleNode("urls");
            XmlNodeList xnList = xn.ChildNodes;

            if (xnList.Count > 0)
            {
                foreach (XmlElement xe in xnList)
                {
                    if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower())
                    {
                        if (xe.Attributes["name"] != null)
                        {
                            model.name = xe.Attributes["name"].Value;
                        }
                        if (xe.Attributes["type"] != null)
                        {
                            model.type = xe.Attributes["type"].Value;
                        }
                        if (xe.Attributes["page"] != null)
                        {
                            model.page = xe.Attributes["page"].Value;
                        }
                        if (xe.Attributes["inherit"] != null)
                        {
                            model.inherit = xe.Attributes["inherit"].Value;
                        }
                        if (xe.Attributes["templet"] != null)
                        {
                            model.templet = xe.Attributes["templet"].Value;
                        }
                        if (xe.Attributes["channel"] != null)
                        {
                            model.channel = xe.Attributes["channel"].Value;
                        }
                        if (xe.Attributes["pagesize"] != null)
                        {
                            model.pagesize = xe.Attributes["pagesize"].Value;
                        }
                        //再次遍历子节点
                        List <Model.url_rewrite_item> lsItems = new List <Model.url_rewrite_item>();
                        foreach (XmlElement xe1 in xe.ChildNodes)
                        {
                            if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                            {
                                Model.url_rewrite_item item = new Model.url_rewrite_item();
                                if (xe1.Attributes["path"] != null)
                                {
                                    item.path = xe1.Attributes["path"].Value;
                                }
                                if (xe1.Attributes["pattern"] != null)
                                {
                                    item.pattern = xe1.Attributes["pattern"].Value;
                                }
                                if (xe1.Attributes["querystring"] != null)
                                {
                                    item.querystring = xe1.Attributes["querystring"].Value;
                                }
                                lsItems.Add(item);
                            }
                        }
                        model.url_rewrite_items = lsItems;
                        return(model);
                    }
                }
            }
            return(null);
        }
Пример #5
0
 /// <summary>
 /// 取得URL配制列表
 /// </summary>
 public List<Model.url_rewrite> GetList(string channel)
 {
     List<Model.url_rewrite> ls = new List<Model.url_rewrite>();
     string filePath = Utils.GetXmlMapPath(MXKeys.FILE_URL_XML_CONFING);
     XmlDocument doc = new XmlDocument();
     doc.Load(filePath);
     XmlNode xn = doc.SelectSingleNode("urls");
     foreach (XmlElement xe in xn.ChildNodes)
     {
         if (xe.NodeType != XmlNodeType.Comment && xe.Name.ToLower() == "rewrite")
         {
             if (xe.Attributes["name"] != null)
             {
                 if (!string.IsNullOrEmpty(channel))
                 {
                     if (xe.Attributes["channel"] != null && channel.ToLower() == xe.Attributes["channel"].Value.ToLower())
                     {
                         Model.url_rewrite model = new Model.url_rewrite();
                         if (xe.Attributes["name"] != null)
                             model.name = xe.Attributes["name"].Value;
                         if (xe.Attributes["type"] != null)
                             model.type = xe.Attributes["type"].Value;
                         if (xe.Attributes["page"] != null)
                             model.page = xe.Attributes["page"].Value;
                         if (xe.Attributes["inherit"] != null)
                             model.inherit = xe.Attributes["inherit"].Value;
                         if (xe.Attributes["templet"] != null)
                             model.templet = xe.Attributes["templet"].Value;
                         if (xe.Attributes["channel"] != null)
                             model.channel = xe.Attributes["channel"].Value;
                         //再次遍历子节点
                         StringBuilder urlRewriteString = new StringBuilder();
                         List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>();
                         foreach (XmlElement xe1 in xe.ChildNodes)
                         {
                             if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                             {
                                 Model.url_rewrite_item item = new Model.url_rewrite_item();
                                 if (xe1.Attributes["path"] != null)
                                     item.path = xe1.Attributes["path"].Value;
                                 if (xe1.Attributes["pattern"] != null)
                                     item.pattern = xe1.Attributes["pattern"].Value;
                                 if (xe1.Attributes["querystring"] != null)
                                     item.querystring = xe1.Attributes["querystring"].Value;
                                 urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                                 lsItems.Add(item);
                             }
                         }
                         model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                         model.url_rewrite_items = lsItems;
                         ls.Add(model);
                     }
                 }
                 else
                 {
                     Model.url_rewrite model = new Model.url_rewrite();
                     if (xe.Attributes["name"] != null)
                         model.name = xe.Attributes["name"].Value;
                     if (xe.Attributes["type"] != null)
                         model.type = xe.Attributes["type"].Value;
                     if (xe.Attributes["page"] != null)
                         model.page = xe.Attributes["page"].Value;
                     if (xe.Attributes["inherit"] != null)
                         model.inherit = xe.Attributes["inherit"].Value;
                     if (xe.Attributes["templet"] != null)
                         model.templet = xe.Attributes["templet"].Value;
                     if (xe.Attributes["channel"] != null)
                         model.channel = xe.Attributes["channel"].Value;
                     //再次遍历子节点
                     StringBuilder urlRewriteString = new StringBuilder();
                     List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>();
                     foreach (XmlElement xe1 in xe.ChildNodes)
                     {
                         if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                         {
                             Model.url_rewrite_item item = new Model.url_rewrite_item();
                             if (xe1.Attributes["path"] != null)
                                 item.path = xe1.Attributes["path"].Value;
                             if (xe1.Attributes["pattern"] != null)
                                 item.pattern = xe1.Attributes["pattern"].Value;
                             if (xe1.Attributes["querystring"] != null)
                                 item.querystring = xe1.Attributes["querystring"].Value;
                             urlRewriteString.Append(item.path + "," + item.pattern + "," + item.querystring + "&"); //组合成字符串
                             lsItems.Add(item);
                         }
                     }
                     model.url_rewrite_str = Utils.DelLastChar(urlRewriteString.ToString(), "&");
                     model.url_rewrite_items = lsItems;
                     ls.Add(model);
                 }
             }
         }
     }
     return ls;
 }
Пример #6
0
 /// <summary>
 /// 取得节点配制信息
 /// </summary>
 public Model.url_rewrite GetInfo(string attrValue)
 {
     Model.url_rewrite model = new Model.url_rewrite();
     string filePath = Utils.GetXmlMapPath(MXKeys.FILE_URL_XML_CONFING);
     XmlDocument doc = new XmlDocument();
     doc.Load(filePath);
     XmlNode xn = doc.SelectSingleNode("urls");
     XmlNodeList xnList = xn.ChildNodes;
     if (xnList.Count > 0)
     {
         foreach (XmlElement xe in xnList)
         {
             if (xe.Attributes["name"].Value.ToLower() == attrValue.ToLower())
             {
                 if (xe.Attributes["name"] != null)
                     model.name = xe.Attributes["name"].Value;
                 if (xe.Attributes["type"] != null)
                     model.type = xe.Attributes["type"].Value;
                 if (xe.Attributes["page"] != null)
                     model.page = xe.Attributes["page"].Value;
                 if (xe.Attributes["inherit"] != null)
                     model.inherit = xe.Attributes["inherit"].Value;
                 if (xe.Attributes["templet"] != null)
                     model.templet = xe.Attributes["templet"].Value;
                 if (xe.Attributes["channel"] != null)
                     model.channel = xe.Attributes["channel"].Value;
                 //再次遍历子节点
                 List<Model.url_rewrite_item> lsItems = new List<Model.url_rewrite_item>();
                 foreach (XmlElement xe1 in xe.ChildNodes)
                 {
                     if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                     {
                         Model.url_rewrite_item item = new Model.url_rewrite_item();
                         if (xe1.Attributes["path"] != null)
                             item.path = xe1.Attributes["path"].Value;
                         if (xe1.Attributes["pattern"] != null)
                             item.pattern = xe1.Attributes["pattern"].Value;
                         if (xe1.Attributes["querystring"] != null)
                             item.querystring = xe1.Attributes["querystring"].Value;
                         lsItems.Add(item);
                     }
                 }
                 model.url_rewrite_items = lsItems;
                 return model;
             }
         }
     }
     return null;
 }