private RewriterConfiguration(XmlDocument doc) { allRules = new RewriterRuleCollection(); XmlNode root = doc.SelectSingleNode("RewriterConfig/Rules"); foreach (XmlNode n in root.ChildNodes) { if (n.NodeType != XmlNodeType.Comment) { string lookFor = n.SelectSingleNode("LookFor").InnerText; string sendTo = n.SelectSingleNode("SendTo").InnerText; bool redirect = false; XmlAttribute redirectAttribute = n.Attributes["Redirect"]; if (redirectAttribute != null) { redirect = SafeConvert.ToBoolean(redirectAttribute.Value); } Regex lookForRegex = new Regex("^" + RewriterUtils.ResolveUrl(applicationPath, lookFor) + "$", RegexOptions.IgnoreCase); RewriterRule rewriterRule = new RewriterRule(lookFor, lookForRegex, sendTo, redirect); allRules.Add(rewriterRule); if (IDENTIFY_USER_URL_REGEX.IsMatch(lookFor)) { string subDomainLookFor = "~" + IDENTIFY_USER_URL_REGEX.Replace(lookFor, ""); rewriterRule.SubDomainLookFor = subDomainLookFor; rewriterRule = new RewriterRule(lookFor, lookForRegex, sendTo, subDomainLookFor, redirect); subDomainRules.Add(rewriterRule); } } } }
/// <summary> /// 添加一个实例到集合 /// </summary> /// <param name="r">一个RewriterRule实例.</param> public void Add(RewriterRule r) { this.InnerList.Add(r); }