private bool DoAdd() { BLL.configs.url_rewrite bll = new BLL.configs.url_rewrite(); Model.configs.url_rewrite model = new Model.configs.url_rewrite(); model.name = txtName.Text.Trim(); model.page = txtPage.Text.Trim(); model.templet = txtTemplet.Text.Trim(); //添加URL重写节点 List<Model.configs.url_rewrite_item> items = new List<Model.configs.url_rewrite_item>(); string[] itemPathArr = Request.Form.GetValues("itemPath"); string[] itemPatternArr = Request.Form.GetValues("itemPattern"); string[] itemQuerystringArr = Request.Form.GetValues("itemQuerystring"); if (itemPathArr != null && itemPatternArr != null && itemQuerystringArr != null) { for (int i = 0; i < itemPathArr.Length; i++) { items.Add(new Model.configs.url_rewrite_item { path = itemPathArr[i], pattern = itemPatternArr[i], querystring = itemQuerystringArr[i] }); } } model.url_rewrite_items = items; if (bll.Add(model)) { AddAdminLog(OSEnums.ActionEnum.Add.ToString(), "添加URL配置信息:" + model.name); //记录日志 return true; } return false; }
private bool DoEdit(string _urlName) { BLL.configs.url_rewrite bll = new BLL.configs.url_rewrite(); Model.configs.url_rewrite model = bll.GetInfo(_urlName); model.page = txtPage.Text.Trim(); model.templet = txtTemplet.Text.Trim(); //添加URL重写节点 List <Model.configs.url_rewrite_item> items = new List <Model.configs.url_rewrite_item>(); string[] itemPathArr = Request.Form.GetValues("itemPath"); string[] itemPatternArr = Request.Form.GetValues("itemPattern"); string[] itemQuerystringArr = Request.Form.GetValues("itemQuerystring"); if (itemPathArr != null && itemPatternArr != null && itemQuerystringArr != null) { for (int i = 0; i < itemPathArr.Length; i++) { items.Add(new Model.configs.url_rewrite_item { path = itemPathArr[i], pattern = itemPatternArr[i], querystring = itemQuerystringArr[i] }); } } model.url_rewrite_items = items; if (bll.Edit(model)) { AddAdminLog(OSEnums.ActionEnum.Edit.ToString(), "修改URL配置信息:" + model.name); //记录日志 return(true); } return(false); }
private void ShowInfo(string _urlName) { BLL.configs.url_rewrite bll = new BLL.configs.url_rewrite(); Model.configs.url_rewrite model = bll.GetInfo(_urlName); txtName.Text = model.name; txtName.ReadOnly = true; txtTemplet.Text = model.templet; txtPage.Text = model.page; //绑定URL配置列表 rptList.DataSource = model.url_rewrite_items; rptList.DataBind(); }
/// <summary> /// 返回URL重写统一链接地址 /// </summary> public string linkurl(string _key, params object[] _params) { Hashtable ht = new BLL.configs.url_rewrite().GetList(); //获得URL配置列表 Model.configs.url_rewrite model = ht[_key] as Model.configs.url_rewrite; //查找指定的URL配置节点 //如果不存在该节点则返回空字符串 if (model == null) { return(string.Empty); } // string requestDomain = HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号 // string requestFirstPath = GetFirstPath();//获得二级目录(不含站点安装目录) string linkStartString = string.Empty; //链接前缀 //如果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); } } } //否则检查该URL配置节点下的子节点 foreach (Model.configs.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); }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.configs.url_rewrite model) { string filePath = Utils.GetXmlMapPath(OSKeys.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() == model.name.ToLower()) { if (!string.IsNullOrEmpty(model.type)) { xe.SetAttribute("type", model.type); } else if (xe.Attributes["type"] != null) { xe.Attributes["type"].RemoveAll(); } if (!string.IsNullOrEmpty(model.page)) { xe.SetAttribute("page", model.page); } else if (xe.Attributes["page"] != null) { xe.Attributes["page"].RemoveAll(); } if (!string.IsNullOrEmpty(model.inherit)) { xe.SetAttribute("inherit", model.inherit); } else if (xe.Attributes["inherit"] != null) { xe.Attributes["inherit"].RemoveAll(); } if (!string.IsNullOrEmpty(model.templet)) { xe.SetAttribute("templet", model.templet); } else if (xe.Attributes["templet"] != null) { xe.Attributes["templet"].RemoveAll(); } if (!string.IsNullOrEmpty(model.channel)) { xe.SetAttribute("channel", model.channel); } else if (xe.Attributes["channel"] != null) { xe.Attributes["channel"].RemoveAll(); } //移除所有的子节点重新添加 XmlNodeList itemXnList = xe.ChildNodes; foreach (XmlElement itemXe in itemXnList) { for (int i = itemXnList.Count - 1; i >= 0; i--) { XmlElement xe2 = (XmlElement)itemXnList.Item(i); xe.RemoveChild(xe2); } } //创建子节点 foreach (Model.configs.url_rewrite_item modelt in model.url_rewrite_items) { XmlElement xeItem = doc.CreateElement("item"); if (!string.IsNullOrEmpty(modelt.path)) { xeItem.SetAttribute("path", modelt.path); } if (!string.IsNullOrEmpty(modelt.pattern)) { xeItem.SetAttribute("pattern", modelt.pattern); } if (!string.IsNullOrEmpty(modelt.querystring)) { xeItem.SetAttribute("querystring", modelt.querystring); } xe.AppendChild(xeItem); } doc.Save(filePath); return(true); } } } return(false); }
/// <summary> /// 取得URL配制列表 /// </summary> public List <Model.configs.url_rewrite> GetList(string channel) { List <Model.configs.url_rewrite> ls = new List <Model.configs.url_rewrite>(); string filePath = Utils.GetXmlMapPath(OSKeys.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.configs.url_rewrite model = new Model.configs.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.configs.url_rewrite_item> lsItems = new List <Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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.configs.url_rewrite model = new Model.configs.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.configs.url_rewrite_item> lsItems = new List <Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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); }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.configs.url_rewrite GetInfo(string attrValue) { Model.configs.url_rewrite model = new Model.configs.url_rewrite(); string filePath = Utils.GetXmlMapPath(OSKeys.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.configs.url_rewrite_item> lsItems = new List <Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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); }
/// <summary> /// 增加节点 /// </summary> public bool Add(Model.configs.url_rewrite model) { try { string filePath = Utils.GetXmlMapPath(OSKeys.FILE_URL_XML_CONFING); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode xn = doc.SelectSingleNode("urls"); XmlElement xe = doc.CreateElement("rewrite"); if (!string.IsNullOrEmpty(model.name)) { xe.SetAttribute("name", model.name); } if (!string.IsNullOrEmpty(model.type)) { xe.SetAttribute("type", model.type); } if (!string.IsNullOrEmpty(model.page)) { xe.SetAttribute("page", model.page); } if (!string.IsNullOrEmpty(model.inherit)) { xe.SetAttribute("inherit", model.inherit); } if (!string.IsNullOrEmpty(model.templet)) { xe.SetAttribute("templet", model.templet); } if (!string.IsNullOrEmpty(model.channel)) { xe.SetAttribute("channel", model.channel.ToString()); } XmlNode newXn = xn.AppendChild(xe); //创建子节点 foreach (Model.configs.url_rewrite_item modelt in model.url_rewrite_items) { XmlElement xeItem = doc.CreateElement("item"); if (!string.IsNullOrEmpty(modelt.path)) { xeItem.SetAttribute("path", modelt.path); } if (!string.IsNullOrEmpty(modelt.pattern)) { xeItem.SetAttribute("pattern", modelt.pattern); } if (!string.IsNullOrEmpty(modelt.querystring)) { xeItem.SetAttribute("querystring", modelt.querystring); } newXn.AppendChild(xeItem); } doc.Save(filePath); return(true); } catch { return(false); } }
/// <summary> /// 修改节点 /// </summary> public bool Edit(Model.configs.url_rewrite model) { return(dal.Edit(model)); }
/// <summary> /// 增加节点 /// </summary> public bool Add(Model.configs.url_rewrite model) { return(dal.Add(model)); }
/// <summary> /// 取得URL配制列表 /// </summary> public List<Model.configs.url_rewrite> GetList(string channel) { List<Model.configs.url_rewrite> ls = new List<Model.configs.url_rewrite>(); string filePath = Utils.GetXmlMapPath(OSKeys.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.configs.url_rewrite model = new Model.configs.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.configs.url_rewrite_item> lsItems = new List<Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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.configs.url_rewrite model = new Model.configs.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.configs.url_rewrite_item> lsItems = new List<Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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; }
/// <summary> /// 取得节点配制信息 /// </summary> public Model.configs.url_rewrite GetInfo(string attrValue) { Model.configs.url_rewrite model = new Model.configs.url_rewrite(); string filePath = Utils.GetXmlMapPath(OSKeys.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.configs.url_rewrite_item> lsItems = new List<Model.configs.url_rewrite_item>(); foreach (XmlElement xe1 in xe.ChildNodes) { if (xe1.NodeType != XmlNodeType.Comment && xe1.Name.ToLower() == "item") { Model.configs.url_rewrite_item item = new Model.configs.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; }