private XmlDocument GetConfigDocument() {
if (_document == null)
{
if (!_initialized)
{
throw new InvalidOperationException(
SR.GetString(SR.XmlSiteMapProvider_Not_Initialized));
}
// Do the error checking here
if (_virtualPath == null)
{
throw new ArgumentException(
SR.GetString(SR.XmlSiteMapProvider_missing_siteMapFile, _siteMapFileAttribute));
}
if (!Path.GetExtension(_virtualPath).Equals(_xmlSiteMapFileExtension, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(
SR.GetString(SR.XmlSiteMapProvider_Invalid_Extension, _virtualPath));
}
// Ensure the appdomain virtualpath has proper trailing slash
_normalizedVirtualPath =
VirtualPathUtility.Combine(AppDomainAppVirtualPathWithTrailingSlash, _virtualPath);
// Make sure the file exists
CheckSiteMapFileExists();
_parentSiteMapFileCollection = new StringCollection();
XmlSiteMapProvider xmlParentProvider = ParentProvider as XmlSiteMapProvider;
if (xmlParentProvider != null && xmlParentProvider._parentSiteMapFileCollection != null)
{
if (xmlParentProvider._parentSiteMapFileCollection.Contains(_normalizedVirtualPath))
{
throw new InvalidOperationException(
SR.GetString(SR.XmlSiteMapProvider_FileName_already_in_use, _virtualPath));
}
// Copy the sitemapfiles in used from parent provider to current provider.
foreach (string filename in xmlParentProvider._parentSiteMapFileCollection)
{
_parentSiteMapFileCollection.Add(filename);
}
}
// Add current sitemap file to the collection
_parentSiteMapFileCollection.Add(_normalizedVirtualPath);
_filename = HostingEnvironment.MapPath(_normalizedVirtualPath);
_document = new ConfigXmlDocument();
}
if (!String.IsNullOrEmpty(_filename))
{
CacheItemRemovedCallback _handler = new CacheItemRemovedCallback(OnConfigFileChange);
CacheDependency _dep = new CacheDependency(_filename);
HttpContext.Current.Cache.Add(GetHashCode().ToString(), "", _dep,
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Normal, _handler);
ResourceKey = (new FileInfo(_filename)).Name;
}
return _document;
}