예제 #1
0
        /// <summary>
        /// 取得URL配制列表
        /// </summary>
        public List <UrlRewriteModel> GetList(string channel)
        {
            List <UrlRewriteModel> ls = new List <UrlRewriteModel>();
            string      filePath      = Utils.GetXmlMapPath(Names.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())
                            {
                                UrlRewriteModel model = new UrlRewriteModel();
                                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 <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                                foreach (XmlElement xe1 in xe.ChildNodes)
                                {
                                    if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                    {
                                        UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                        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
                        {
                            UrlRewriteModel model = new UrlRewriteModel();
                            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 <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                            foreach (XmlElement xe1 in xe.ChildNodes)
                            {
                                if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                                {
                                    UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                    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);
        }
예제 #2
0
        /// <summary>
        /// 根据请求的路径进行匹配配置文件当中是否存在此节点对象
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public UrlRewriteModel GetInfoModel_RequestPagePath(string path)
        {
            UrlRewriteModel model    = new UrlRewriteModel();
            string          filePath = Utils.GetXmlMapPath(Names.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)
                {
                    string panduan = "/aspx/YTSTemp/" + xe.Attributes["page"].Value.ToLower();
                    if (panduan.ToLower() == path.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 <UrlRewrite_ItemModel> lsItems = new List <UrlRewrite_ItemModel>();
                        foreach (XmlElement xe1 in xe.ChildNodes)
                        {
                            if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item")
                            {
                                UrlRewrite_ItemModel item = new UrlRewrite_ItemModel();
                                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);
        }