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));
        }
        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)
                    {
                        string originalResult = null;
                        try
                        {
                            originalResult = this.MapPathActual(siteID, path);
                            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);
                            }
                        }
                        catch (Exception exception)
                        {
                            if (!HttpRuntime.IsMapPathRelaxed)
                            {
                                info.CachedException = exception;
                                info.Evaluated       = true;
                                throw;
                            }
                            originalResult = HttpRuntime.GetRelaxedMapPathResult(null);
                        }
                        if (originalResult != null)
                        {
                            info.MapPathResult = originalResult;
                            info.Evaluated     = true;
                        }
                    }
                }
            }
            if (info.CachedException != null)
            {
                throw info.CachedException;
            }
            return(this.MatchResult(path2, info.MapPathResult));
        }
        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);
        }
 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)
             {
                 string originalResult = null;
                 try
                 {
                     originalResult = this.MapPathActual(siteID, path);
                     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);
                     }
                 }
                 catch (Exception exception)
                 {
                     if (!HttpRuntime.IsMapPathRelaxed)
                     {
                         info.CachedException = exception;
                         info.Evaluated = true;
                         throw;
                     }
                     originalResult = HttpRuntime.GetRelaxedMapPathResult(null);
                 }
                 if (originalResult != null)
                 {
                     info.MapPathResult = originalResult;
                     info.Evaluated = true;
                 }
             }
         }
     }
     if (info.CachedException != null)
     {
         throw info.CachedException;
     }
     return this.MatchResult(path2, info.MapPathResult);
 }