예제 #1
0
        /// <summary>
        /// Parse an IIS rewrite section into a list of <see cref="IISUrlRewriteRule"/>s.
        /// </summary>
        /// <param name="reader">The reader containing the rewrite XML</param>
        public IList <IISUrlRewriteRule> Parse(TextReader reader)
        {
            var xmlDoc  = XDocument.Load(reader, LoadOptions.SetLineInfo);
            var xmlRoot = xmlDoc.Descendants(RewriteTags.Rewrite).FirstOrDefault();

            if (xmlRoot == null)
            {
                return(null);
            }

            _inputParser = new InputParser(RewriteMapParser.Parse(xmlRoot));

            var result = new List <IISUrlRewriteRule>();

            ParseRules(xmlRoot.Descendants(RewriteTags.GlobalRules).FirstOrDefault(), result, global: true);
            ParseRules(xmlRoot.Descendants(RewriteTags.Rules).FirstOrDefault(), result, global: false);
            return(result);
        }
        /// <summary>
        /// Parse an IIS rewrite section into a list of <see cref="IISUrlRewriteRule"/>s.
        /// </summary>
        /// <param name="reader">The reader containing the rewrite XML</param>
        /// <param name="alwaysUseManagedServerVariables">Determines whether server variables will be sourced from the managed server</param>
        public IList <IISUrlRewriteRule> Parse(TextReader reader, bool alwaysUseManagedServerVariables)
        {
            var xmlDoc  = XDocument.Load(reader, LoadOptions.SetLineInfo);
            var xmlRoot = xmlDoc.Descendants(RewriteTags.Rewrite).FirstOrDefault();

            if (xmlRoot == null)
            {
                throw new InvalidUrlRewriteFormatException(new XElement(RewriteTags.Rewrite), "The root element '<rewrite>' is missing");
            }

            _inputParser = new InputParser(RewriteMapParser.Parse(xmlRoot), alwaysUseManagedServerVariables);

            var result = new List <IISUrlRewriteRule>();

            ParseRules(xmlRoot.Descendants(RewriteTags.GlobalRules).FirstOrDefault(), result, global: true);
            ParseRules(xmlRoot.Descendants(RewriteTags.Rules).FirstOrDefault(), result, global: false);
            return(result);
        }