ProcessHostServerConfig() { if (null == HostingEnvironment.SupportFunctions) { ProcessHostConfigUtils.InitStandaloneConfig(); } else { IProcessHostSupportFunctions fns = HostingEnvironment.SupportFunctions; if (null != fns) { IntPtr configSystem = fns.GetNativeConfigurationSystem(); Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem"); if (IntPtr.Zero != configSystem) { // won't fail if valid pointer // no cleanup needed, we don't own instance UnsafeIISMethods.MgdSetNativeConfiguration(configSystem); } } } _siteNameForCurrentApplication = HostingEnvironment.SiteNameNoDemand; if (_siteNameForCurrentApplication == null) { _siteNameForCurrentApplication = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT); } }
string IServerConfig.GetSiteNameFromSiteID(string siteID) { uint num; if (!uint.TryParse(siteID, out num)) { return(string.Empty); } return(ProcessHostConfigUtils.GetSiteNameFromId(num)); }
void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID) { Debug.Trace("MapPath", "ProcHostMP.ResolveSiteArgument(" + siteArgument + ")\n"); if (String.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT))) { siteName = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT); siteID = ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING; } else { siteName = String.Empty; siteID = String.Empty; string resolvedName = null; if (IISMapPath.IsSiteId(siteArgument)) { uint id; if (UInt32.TryParse(siteArgument, out id)) { resolvedName = ProcessHostConfigUtils.GetSiteNameFromId(id); } } // try to resolve the string else { uint id = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument); if (id != 0) { siteID = id.ToString(CultureInfo.InvariantCulture); siteName = siteArgument; return; } } if (!String.IsNullOrEmpty(resolvedName)) { siteName = resolvedName; siteID = siteArgument; } else { siteName = siteArgument; siteID = String.Empty; } } Debug.Assert(!String.IsNullOrEmpty(siteName), "!String.IsNullOrEmpty(siteName), siteArg=" + siteArgument); }
string IServerConfig.GetSiteNameFromSiteID(string siteID) { uint siteIDValue; if (!UInt32.TryParse(siteID, out siteIDValue)) { Debug.Assert(false, "siteID is not numeric"); return(String.Empty); } return(ProcessHostConfigUtils.GetSiteNameFromId(siteIDValue)); }
void IConfigMapPath.ResolveSiteArgument(string siteArgument, out string siteName, out string siteID) { if ((string.IsNullOrEmpty(siteArgument) || StringUtil.EqualsIgnoreCase(siteArgument, "1")) || StringUtil.EqualsIgnoreCase(siteArgument, ProcessHostConfigUtils.GetSiteNameFromId(1))) { siteName = ProcessHostConfigUtils.GetSiteNameFromId(1); siteID = "1"; } else { siteName = string.Empty; siteID = string.Empty; string siteNameFromId = null; if (IISMapPath.IsSiteId(siteArgument)) { uint num; if (uint.TryParse(siteArgument, out num)) { siteNameFromId = ProcessHostConfigUtils.GetSiteNameFromId(num); } } else { uint num2 = UnsafeIISMethods.MgdResolveSiteName(IntPtr.Zero, siteArgument); if (num2 != 0) { siteID = num2.ToString(CultureInfo.InvariantCulture); siteName = siteArgument; return; } } if (!string.IsNullOrEmpty(siteNameFromId)) { siteName = siteNameFromId; siteID = siteArgument; } else { siteName = siteArgument; siteID = string.Empty; } } }
private ProcessHostServerConfig() { if (HostingEnvironment.SupportFunctions == null) { ProcessHostConfigUtils.InitStandaloneConfig(); } else { IProcessHostSupportFunctions supportFunctions = HostingEnvironment.SupportFunctions; if (supportFunctions != null) { IntPtr nativeConfigurationSystem = supportFunctions.GetNativeConfigurationSystem(); if (IntPtr.Zero != nativeConfigurationSystem) { UnsafeIISMethods.MgdSetNativeConfiguration(nativeConfigurationSystem); } } } this._siteNameForCurrentApplication = HostingEnvironment.SiteNameNoDemand; if (this._siteNameForCurrentApplication == null) { this._siteNameForCurrentApplication = ProcessHostConfigUtils.GetSiteNameFromId(1); } }
private string MapPathCaching(string siteID, VirtualPath path) { // UrlMetaDataSlidingExpiration config setting controls // the duration of all cached items related to url metadata. bool doNotCache = CachedPathData.DoNotCacheUrlMetadata; TimeSpan slidingExpiration = CachedPathData.UrlMetadataSlidingExpiration; // store a single variation of the path VirtualPath originalPath = path; MapPathCacheInfo cacheInfo; if (doNotCache) { cacheInfo = new MapPathCacheInfo(); } else { // Check if it's in the cache String cacheKey = CacheInternal.PrefixMapPath + siteID + path.VirtualPathString; cacheInfo = (MapPathCacheInfo)HttpRuntime.CacheInternal.Get(cacheKey); // If not in cache, add it to the cache if (cacheInfo == null) { cacheInfo = new MapPathCacheInfo(); // Add to the cache. // No need to have a lock here. UtcAdd will add the entry if it doesn't exist. // If it does exist, the existing value will be returned (Dev10 Bug 755034). object existingEntry = HttpRuntime.CacheInternal.UtcAdd( cacheKey, cacheInfo, null, Cache.NoAbsoluteExpiration, slidingExpiration, CacheItemPriority.Default, null); if (existingEntry != null) { cacheInfo = existingEntry as MapPathCacheInfo; } } } // If not been evaluated, then evaluate it if (!cacheInfo.Evaluated) { lock (cacheInfo) { if (!cacheInfo.Evaluated && HttpRuntime.IsMapPathRelaxed) { ////////////////////////////////////////////////////////////////// // Verify that the parent path is valid. If parent is invalid, then set this to invalid if (path.VirtualPathString.Length > 1) { VirtualPath vParent = path.Parent; if (vParent != null) { string parentPath = vParent.VirtualPathString; if (parentPath.Length > 1 && StringUtil.StringEndsWith(parentPath, '/')) // Trim the extra trailing / if there is one { vParent = VirtualPath.Create(parentPath.Substring(0, parentPath.Length - 1)); } try { string parentMapPathResult = MapPathCaching(siteID, vParent); if (parentMapPathResult == HttpRuntime.GetRelaxedMapPathResult(null)) { // parent is invalid! cacheInfo.MapPathResult = parentMapPathResult; cacheInfo.Evaluated = true; } } catch { cacheInfo.MapPathResult = HttpRuntime.GetRelaxedMapPathResult(null); cacheInfo.Evaluated = true; } } } } if (!cacheInfo.Evaluated) { try { string physicalPath = null; uint siteIDValue; if (UInt32.TryParse(siteID, out siteIDValue)) { string siteName = ProcessHostConfigUtils.GetSiteNameFromId(siteIDValue); physicalPath = ProcessHostConfigUtils.MapPathActual(siteName, path); } if (physicalPath != null && physicalPath.Length == 2 && physicalPath[1] == ':') { physicalPath += "\\"; } // Throw if the resulting physical path is not canonical, to prevent potential // security issues (VSWhidbey 418125) if (HttpRuntime.IsMapPathRelaxed) { physicalPath = HttpRuntime.GetRelaxedMapPathResult(physicalPath); } if (FileUtil.IsSuspiciousPhysicalPath(physicalPath)) { if (HttpRuntime.IsMapPathRelaxed) { physicalPath = HttpRuntime.GetRelaxedMapPathResult(null); } else { throw new HttpException(SR.GetString(SR.Cannot_map_path, path)); } } cacheInfo.MapPathResult = physicalPath; } catch (Exception e) { if (HttpRuntime.IsMapPathRelaxed) { cacheInfo.MapPathResult = HttpRuntime.GetRelaxedMapPathResult(null); } else { cacheInfo.CachedException = e; cacheInfo.Evaluated = true; throw; } } cacheInfo.Evaluated = true; } } } // Throw an exception if required if (cacheInfo.CachedException != null) { throw cacheInfo.CachedException; } return(MatchResult(originalPath, cacheInfo.MapPathResult)); }
void IConfigMapPath.GetDefaultSiteNameAndID(out string siteName, out string siteID) { Debug.Trace("MapPath", "ProcHostMP.GetDefaultSiteNameAndID\n"); siteID = ProcessHostConfigUtils.DEFAULT_SITE_ID_STRING; siteName = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT); }
private string MapPathCaching(string siteID, VirtualPath path) { VirtualPath path2 = path; string key = "f" + siteID + path.VirtualPathString; MapPathCacheInfo info = (MapPathCacheInfo)HttpRuntime.CacheInternal.Get(key); if (info == null) { lock (this._mapPathCacheLock) { info = (MapPathCacheInfo)HttpRuntime.CacheInternal.Get(key); if (info == null) { info = new MapPathCacheInfo(); HttpRuntime.CacheInternal.UtcInsert(key, info, null, DateTime.UtcNow.AddMinutes(10.0), Cache.NoSlidingExpiration); } } } if (!info.Evaluated) { lock (info) { if ((!info.Evaluated && HttpRuntime.IsMapPathRelaxed) && (path.VirtualPathString.Length > 1)) { VirtualPath parent = path.Parent; if (parent != null) { string virtualPathString = parent.VirtualPathString; if ((virtualPathString.Length > 1) && StringUtil.StringEndsWith(virtualPathString, '/')) { parent = VirtualPath.Create(virtualPathString.Substring(0, virtualPathString.Length - 1)); } try { string str3 = this.MapPathCaching(siteID, parent); if (str3 == HttpRuntime.GetRelaxedMapPathResult(null)) { info.MapPathResult = str3; info.Evaluated = true; } } catch { info.MapPathResult = HttpRuntime.GetRelaxedMapPathResult(null); info.Evaluated = true; } } } if (!info.Evaluated) { try { uint num; string originalResult = null; if (uint.TryParse(siteID, out num)) { originalResult = ProcessHostConfigUtils.MapPathActual(ProcessHostConfigUtils.GetSiteNameFromId(num), path); } if (((originalResult != null) && (originalResult.Length == 2)) && (originalResult[1] == ':')) { originalResult = originalResult + @"\"; } if (HttpRuntime.IsMapPathRelaxed) { originalResult = HttpRuntime.GetRelaxedMapPathResult(originalResult); } if (FileUtil.IsSuspiciousPhysicalPath(originalResult)) { if (!HttpRuntime.IsMapPathRelaxed) { throw new HttpException(System.Web.SR.GetString("Cannot_map_path", new object[] { path })); } originalResult = HttpRuntime.GetRelaxedMapPathResult(null); } info.MapPathResult = originalResult; } catch (Exception exception) { if (!HttpRuntime.IsMapPathRelaxed) { info.CachedException = exception; info.Evaluated = true; throw; } info.MapPathResult = HttpRuntime.GetRelaxedMapPathResult(null); } info.Evaluated = true; } } } if (info.CachedException != null) { throw info.CachedException; } return(this.MatchResult(path2, info.MapPathResult)); }
void IConfigMapPath.GetDefaultSiteNameAndID(out string siteName, out string siteID) { siteID = "1"; siteName = ProcessHostConfigUtils.GetSiteNameFromId(1); }