private ConfigXmlReader FindSection(string [] keys, SectionXmlInfo sectionXmlInfo, out int lineNumber) {
lineNumber = 0;
ConfigXmlReader section = null;
try {
using (Impersonate()) {
using (Stream stream = Host.OpenStreamForRead(sectionXmlInfo.Filename)) {
if ( !_flags[SupportsRefresh]
&& (stream == null || HasStreamChanged(sectionXmlInfo.Filename, sectionXmlInfo.StreamVersion))) {
throw new ConfigurationErrorsException(SR.GetString(SR.Config_file_has_changed), sectionXmlInfo.Filename, 0);
}
if (stream != null) {
using (XmlUtil xmlUtil = new XmlUtil(stream, sectionXmlInfo.Filename, true)) {
if (sectionXmlInfo.SubPath == null) {
section = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
}
else {
// search children of <configuration> for <location>
xmlUtil.ReadToNextElement();
while (xmlUtil.Reader.Depth > 0) {
if (xmlUtil.Reader.Name == KEYWORD_LOCATION) {
bool locationValid = false;
string locationSubPathAttribute = xmlUtil.Reader.GetAttribute(KEYWORD_LOCATION_PATH);
try {
locationSubPathAttribute = NormalizeLocationSubPath(locationSubPathAttribute, xmlUtil);
locationValid = true;
}
catch (ConfigurationException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.NonSpecific);
}
if (locationValid &&
StringUtil.EqualsIgnoreCase(sectionXmlInfo.SubPath, locationSubPathAttribute)) {
section = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
if (section != null)
break;
}
}
xmlUtil.SkipToNextElement();
}
}
// Throw accumulated errors
ThrowIfParseErrors(xmlUtil.SchemaErrors);
}
}
}
}
}
// Don't allow frames up the stack to run exception filters while impersonated.
catch {
throw;
}
return section;
}