public Configuration GetWebConfiguration()
{
if (_configuration != null)
{
return _configuration;
}
string root = null;
foreach (VirtualDirectory child in VirtualDirectories)
{
if (child.Path == VirtualDirectory.RootPath)
{
root = child.PhysicalPath;
break;
}
}
if (this.IsRoot())
{
var server = Server.GetConfigurationCache().FileContext;
if (root == null)
{
var site = new Configuration(new FileContext(Server, null, server, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
return (_configuration = site);
}
else
{
var physicalPath = Server.GetPhysicalPath(root);
var siteFile = System.IO.Path.Combine(physicalPath,
"web.config").ExpandIisExpressEnvironmentVariables();
Server.CleanSiteFile(siteFile);
// TODO: test ACL to set ReadOnly.
var site = new Configuration(new FileContext(Server, siteFile, server, Site.Name, false, false, this.Server.ReadOnly));
return (_configuration = site);
}
}
string start = null;
Configuration parent = null;
while (parent == null)
{
var parentPath = (start ?? Path).GetParentPath();
foreach (Application app in Site.Applications)
{
if (app.Path != parentPath)
{
continue;
}
parent = app.GetWebConfiguration();
break;
}
if (start == parentPath)
{
break;
}
start = parentPath;
}
if (root == null)
{
var app = new Configuration(new FileContext(Server, null, parent?.FileContext, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
return (_configuration = app);
}
var fullPath = Site.Name + Path;
var appFile = System.IO.Path.Combine(root, "web.config");
// TODO: test ACL to set ReadOnly.
return (_configuration = new Configuration(new FileContext(Server, appFile, parent?.FileContext, fullPath, false, false, this.Server.ReadOnly)));
}