Exemple #1
0
        private static string ResolveThemedContent(RequestContext requestContext, VirtualPathProvider vpp, string contentPath)
        {
            string themeFolderPath = requestContext.RouteData.DataTokens["ThemeViewEngine.ThemeFolderPath"] as string
                                     ?? Url.ResolveTokens(Url.ThemesUrlToken);

            string theme = requestContext.HttpContext.GetTheme();

            if (!string.IsNullOrEmpty(theme))
            {
                string themeContentPath = themeFolderPath + theme + contentPath.TrimStart('~');
                if (vpp.FileExists(themeContentPath))
                {
                    return(Url.ToAbsolute(themeContentPath));
                }
            }

            string defaultThemeContentPath = themeFolderPath + "Default" + contentPath.TrimStart('~');

            if (vpp.FileExists(defaultThemeContentPath))
            {
                return(Url.ToAbsolute(defaultThemeContentPath));
            }

            return(Url.ToAbsolute(contentPath));
        }
        public override bool FileExists(string virtualPath)
        {
            var result = GetResolveResult(virtualPath);

            if (result != null)
            {
                if (!result.IsBased)
                {
                    return(true);
                }
                else
                {
                    if (result.Query.HasValue() && result.Query.IndexOf('.') >= 0)
                    {
                        // libSass tries to locate files by appending .[s]css extension to our querystring. Prevent this shit!
                        return(false);
                    }
                    else
                    {
                        // Let system VPP check for this file
                        virtualPath = result.ResultVirtualPath ?? result.OriginalVirtualPath;
                    }
                }
            }

            return(_previous.FileExists(virtualPath));
        }
Exemple #3
0
        internal Chart(HttpContextBase httpContext, VirtualPathProvider virtualPathProvider, int width, int height,
                       string theme = null, string themePath = null)
        {
            Debug.Assert(httpContext != null);

            if (width < 0)
            {
                throw new ArgumentOutOfRangeException("width", String.Format(CultureInfo.CurrentCulture,
                                                                             CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height", String.Format(CultureInfo.CurrentCulture,
                                                                              CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            _httpContext         = httpContext;
            _virtualPathProvider = virtualPathProvider;
            _width  = width;
            _height = height;
            _theme  = theme;

            // path must be app-relative in case chart is rendered from handler in different directory
            if (!String.IsNullOrEmpty(themePath))
            {
                _themePath = VirtualPathUtil.ResolvePath(TemplateStack.GetCurrentTemplate(httpContext), httpContext, themePath);
                if (!_virtualPathProvider.FileExists(_themePath))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, HelpersResources.Chart_ThemeFileNotFound, _themePath), "themePath");
                }
            }
        }
        /// <summary>创建实例。Start和Layout会调用这里</summary>
        /// <param name="virtualPath"></param>
        /// <returns></returns>
        public Object CreateInstance(String virtualPath)
        {
            virtualPath = EnsureVirtualPathPrefix(virtualPath);

            // 两个条件任意一个满足即可使用物理文件
            // 如果不要求取代物理文件,并且虚拟文件存在,则使用物理文件创建
            if (!PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase)));
            }

            // 如果使用较新的物理文件,且物理文件的确较新,则使用物理文件创建
            if (UsePhysicalViewsIfNewer && IsPhysicalFileNewer(virtualPath))
            {
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebViewPage)));
            }

            // 最后使用内嵌类创建
            Type type;

            if (_mappings.TryGetValue(virtualPath, out type))
            {
                return(ViewPageActivator.Create(null, type));
            }

            return(null);
        }
Exemple #5
0
        /// <summary>创建实例。Start和Layout会调用这里</summary>
        /// <param name="virtualPath"></param>
        /// <returns></returns>
        public Object CreateInstance(String virtualPath)
        {
            ViewMapping viewMapping;

            // 如果没有该映射,则直接返回空
            if (!_mappings.TryGetValue(virtualPath, out viewMapping))
            {
                return(null);
            }

            var asm = viewMapping.ViewAssembly;

            // 两个条件任意一个满足即可使用物理文件
            // 如果不要求取代物理文件,并且虚拟文件存在,则使用物理文件创建
            if (!asm.PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase)));
            }

            // 如果使用较新的物理文件,且物理文件的确较新,则使用物理文件创建
            if (asm.UsePhysicalViewsIfNewer && asm.IsPhysicalFileNewer(virtualPath))
            {
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebViewPage)));
            }

            // 最后使用内嵌类创建
            return(ViewPageActivator.Create(null, viewMapping.Type));
        }
Exemple #6
0
        /// <summary>
        /// 在指定虚拟路径上溯搜索指定文件名的文件
        /// </summary>
        /// <param name="provider">自定义的虚拟路径提供程序</param>
        /// <param name="virtualPath">要搜索的虚拟路径</param>
        /// <param name="fileNames">要搜索的文件名列表</param>
        /// <returns>返回找到的文件路径,若无法找到匹配的文件,则返回null</returns>
        public static string FallbackSearch(VirtualPathProvider provider, string virtualPath, params string[] fileNames)
        {
            if (!VirtualPathUtility.IsAppRelative(virtualPath))
            {
                throw VirtualPathFormatError("virtualPath");
            }


            while (true)
            {
                virtualPath = GetParentDirectory(virtualPath);
                if (virtualPath == null)
                {
                    break;
                }

                foreach (var name in fileNames)
                {
                    var filePath = VirtualPathUtility.Combine(virtualPath, name);
                    if (provider.FileExists(filePath))
                    {
                        return(filePath);
                    }
                }
            }

            return(null);
        }
Exemple #7
0
        protected string TryFindViewFromViewModel(Cache cache, object viewModel)
        {
            if (viewModel != null)
            {
                var viewModelType = viewModel.GetType();
                var cacheKey      = "ViewModelViewName_" + viewModelType.FullName;
                var cachedValue   = (string)cache.Get(cacheKey);
                if (cachedValue != null)
                {
                    return(cachedValue != NoVirtualPathCacheValue ? cachedValue : null);
                }
                while (viewModelType != typeof(object))
                {
                    var viewModelName = viewModelType.Name;
                    var namespacePart = viewModelType.Namespace.Substring("FODT.".Length);
                    var virtualPath   = "~/" + namespacePart.Replace(".", "/") + "/" + viewModelName.Replace("ViewModel", "") + ".cshtml";
                    if (Exists(virtualPath) || VirtualPathProvider.FileExists(virtualPath))
                    {
                        cache.Insert(cacheKey, virtualPath, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
                        return(virtualPath);
                    }
                    viewModelType = viewModelType.BaseType;
                }

                // no view found
                cache.Insert(cacheKey, NoVirtualPathCacheValue, null /* dependencies */, Cache.NoAbsoluteExpiration, _defaultCacheTimeSpan);
            }
            return(null);
        }
Exemple #8
0
        public object CreateInstance(string virtualPath)
        {
            virtualPath = EnsureVirtualPathPrefix(virtualPath);
            Type type;

            if (!PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                // If we aren't pre-empting physical files, use the BuildManager to create _ViewStart instances if the file exists on disk.

                // There is no build provider registered for the extension '.cshtml'.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase)));
            }

            if (UsePhysicalViewsIfNewer && IsPhysicalFileNewer(virtualPath))
            {
                // If the physical file on disk is newer and the user's opted in this behavior, serve it instead.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebViewPage)));
            }

            if (_mappings.TryGetValue(virtualPath, out type))
            {
                return(_viewPageActivator.Create((ControllerContext)null, type));
            }
            return(null);
        }
Exemple #9
0
        internal static bool RemapHandlerForBundleRequests(HttpApplication app)
        {
            HttpContextBase context = new HttpContextWrapper(app.Context);

            // Don't block requests to existing files or directories
            string requestPath      = context.Request.AppRelativeCurrentExecutionFilePath;
            VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;

            if (vpp.FileExists(requestPath) || vpp.DirectoryExists(requestPath))
            {
                return(false);
            }

            string bundleRequestPath = GetBundleUrlFromContext(context);

            // Check if this request matches a bundle in the app
            Bundle requestBundle = BundleTable.Bundles.GetBundleFor(bundleRequestPath);

            if (requestBundle != null)
            {
                context.RemapHandler(new BundleHandler(requestBundle, bundleRequestPath));
                return(true);
            }

            return(false);
        }
Exemple #10
0
        /// <summary>
        /// 在指定虚拟路径上溯搜索指定文件名的文件
        /// </summary>
        /// <param name="provider">自定义的虚拟路径提供程序</param>
        /// <param name="virtualPath">要搜索的虚拟路径</param>
        /// <param name="fileNames">要搜索的文件名列表</param>
        /// <returns>返回找到的文件路径,若无法找到匹配的文件,则返回null</returns>
        internal static string FallbackSearch(VirtualPathProvider provider, string virtualPath, params string[] fileNames)
        {
            if (!VirtualPathUtility.IsAppRelative(virtualPath))
            {
                throw VirtualPathFormatError("virtualPath");
            }

            var directory = VirtualPathUtility.GetDirectory(virtualPath);

            while (true)
            {
                foreach (var name in fileNames)
                {
                    var filePath = VirtualPathUtility.Combine(directory, name);
                    if (provider.FileExists(filePath))
                    {
                        return(filePath);
                    }
                }

                if (directory == "~/")
                {
                    break;
                }

                directory = VirtualPathUtility.Combine(directory, "../");
            }

            return(null);
        }
        public object CreateInstance(string virtualPath)
        {
            virtualPath = PrecompiledMvcEngine.EnsureVirtualPathPrefix(virtualPath);

            ViewMapping mapping;

            if (!_mappings.TryGetValue(virtualPath, out mapping))
            {
                return(null);
            }

            if (!mapping.ViewAssembly.PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                // If we aren't pre-empting physical files, use the BuildManager to create _ViewStart instances if the file exists on disk.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase)));
            }

            if (mapping.ViewAssembly.UsePhysicalViewsIfNewer && mapping.ViewAssembly.IsPhysicalFileNewer(virtualPath))
            {
                // If the physical file on disk is newer and the user's opted in this behavior, serve it instead.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebViewPage)));
            }

            return(_viewPageActivator.Create((ControllerContext)null, mapping.Type));
        }
Exemple #12
0
        public override bool FileExists(string virtualPath)
        {
            var styleResult = ThemeHelper.IsStyleSheet(virtualPath);

            if (styleResult != null && (styleResult.IsThemeVars || styleResult.IsModuleImports))
            {
                return(true);
            }

            var result = GetResolveResult(virtualPath);

            if (result != null)
            {
                if (!result.IsExplicit)
                {
                    return(true);
                }
                else
                {
                    virtualPath = result.OriginalVirtualPath;
                }
            }

            return(_previous.FileExists(virtualPath));
        }
        public object CreateInstance(string virtualPath)
        {
            var routeData = ((MvcHandler)HttpContext.Current.Handler).RequestContext.RouteData;

            ViewMapping mapping;

            if (!_mappings[_assemblySelector(routeData.Values, _mappings.Keys)].TryGetValue(virtualPath, out mapping))
            {
                return(null);
            }

            if (!mapping.ViewAssembly.PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                // If we aren't pre-empting physical files, use the BuildManager to create _ViewStart instances if the file exists on disk.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebPageRenderingBase)));
            }

            if (mapping.ViewAssembly.UsePhysicalViewsIfNewer && mapping.ViewAssembly.IsPhysicalFileNewer(virtualPath))
            {
                // If the physical file on disk is newer and the user's opted in this behavior, serve it instead.
                return(BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(WebViewPage)));
            }

            return(_viewPageActivator.Create((ControllerContext)null, mapping.Type));
        }
        public RouteData GetRouteData(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            if (httpContext.Request == null)
            {
                throw new ArgumentException("The context does not contain any request data.", "httpContext");
            }
            if (Count == 0)
            {
                return(null);
            }
            if (!RouteExistingFiles)
            {
                var path = httpContext.Request.AppRelativeCurrentExecutionFilePath;
                VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;
                if (path != "~/" && vpp != null && (vpp.FileExists(path) || vpp.DirectoryExists(path)))
                {
                    return(null);
                }
            }
            foreach (RouteBase rb in this)
            {
                var rd = rb.GetRouteData(httpContext);
                if (rd != null)
                {
                    return(rd);
                }
            }

            return(null);
        }
Exemple #15
0
        private static HelpTopic CreateTopic(string virtualPath)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            virtualPath = VirtualPathUtility.Combine(helpEntriesVirtualPath, virtualPath);


            if (VirtualPathProvider.DirectoryExists(virtualPath))
            {
                return(new HelpCategory(virtualPath));
            }

            else if (VirtualPathProvider.FileExists(virtualPath))
            {
                return(new HelpEntry(virtualPath));
            }

            else
            {
                return(null);
            }
        }
        protected string FindMaster(string masterName)
        {
            if (masterName.StartsWith("~/") && VirtualPathProvider.FileExists(masterName))
            {
                return(masterName);
            }

            if (masterName.StartsWith("~/") && VirtualPathProvider.FileExists(masterName + ".master"))
            {
                return(masterName + ".master");
            }

            if (VirtualPathProvider.FileExists("~/Views/" + masterName))
            {
                return("~/Views/" + masterName);
            }

            if (VirtualPathProvider.FileExists("~/Views/" + masterName + ".master"))
            {
                return("~/Views/" + masterName + ".master");
            }

            if (VirtualPathProvider.FileExists("~/Views/Shared/" + masterName))
            {
                return("~/Views/Shared" + masterName);
            }

            if (VirtualPathProvider.FileExists("~/Views/Shared/" + masterName + ".master"))
            {
                return("~/Views/Shared" + masterName + ".master");
            }

            return(null);
        }
Exemple #17
0
        /// <summary>文件是否存在。如果存在,则由当前引擎创建视图</summary>
        /// <param name="controllerContext"></param>
        /// <param name="virtualPath"></param>
        /// <returns></returns>
        protected override Boolean FileExists(ControllerContext controllerContext, String virtualPath)
        {
            ViewMapping viewMapping;

            // 如果映射表不存在,就不要掺合啦
            if (!_mappings.TryGetValue(virtualPath, out viewMapping))
            {
                return(false);
            }

            //if (!Exists(virtualPath)) return false;

            var asm = viewMapping.ViewAssembly;

            // 两个条件任意一个满足即可使用物理文件
            // 如果不要求取代物理文件,并且虚拟文件存在,则使用物理文件创建
            if (!asm.PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                return(false);
            }

            // 如果使用较新的物理文件,且物理文件的确较新,则使用物理文件创建
            if (asm.UsePhysicalViewsIfNewer && asm.IsPhysicalFileNewer(virtualPath))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>文件是否存在。如果存在,则由当前引擎创建视图</summary>
        /// <param name="controllerContext"></param>
        /// <param name="virtualPath"></param>
        /// <returns></returns>
        protected override Boolean FileExists(ControllerContext controllerContext, String virtualPath)
        {
            virtualPath = EnsureVirtualPathPrefix(virtualPath);

            // 如果映射表不存在,就不要掺合啦
            if (!Exists(virtualPath))
            {
                return(false);
            }

            // 两个条件任意一个满足即可使用物理文件
            // 如果不要求取代物理文件,并且虚拟文件存在,则使用物理文件创建
            if (!PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                return(false);
            }

            // 如果使用较新的物理文件,且物理文件的确较新,则使用物理文件创建
            if (UsePhysicalViewsIfNewer && IsPhysicalFileNewer(virtualPath))
            {
                return(false);
            }

            return(true);
        }
Exemple #19
0
        protected string GetVirtualPathAttribute(IDictionary <string, string> attribs, string name, bool checkFileExists)
        {
            string str = GetNonEmptyAttribute(attribs, name);

            if (str != null)
            {
                VirtualPathProvider vpp = this.VirtualPathProvider;

                string combined;

                try {
                    combined = vpp.CombineVirtualPaths(this.VirtualPath, str);
                } catch (Exception ex) {
                    throw CreateParseException(ex.Message);
                }

                if (checkFileExists &&
                    !vpp.FileExists(combined))
                {
                    throw CreateParseException("The file '{0}' does not exist.", str);
                }

                return(combined);
            }
            else
            {
                return(null);
            }
        }
Exemple #20
0
        private string GetImportedPath(HttpContext context, VirtualPathProvider vpp, string path, string line)
        {
            if (Resources.Register.Debug)
            {
                return(null);
            }
            if (!line.StartsWith("@import"))
            {
                return(null);
            }

            string url = importUrlExpression.Match(line).Groups["url"].Value;

            if (!string.IsNullOrEmpty(url))
            {
                bool isRelative = !url.StartsWith("~") && !url.StartsWith("/");
                if (!isRelative)
                {
                    return(null);
                }

                url = Normalize(url, VirtualPathUtility.GetDirectory(path));
                if (vpp.FileExists(url))
                {
                    return(url);
                }
            }
            return(null);
        }
        public virtual FileEngineResult FindFile(string fileName)
        {
            if (fileName.Contains("?"))
            {
                fileName = fileName.Substring(0, fileName.IndexOf('?'));
            }

            if (!fileName.StartsWith("/"))
            {
                fileName = "/" + fileName;
            }

            var originalFileName = fileName;

            fileName = rootPath + fileName;

            if (VirtualPathProvider.FileExists(fileName))
            {
                return(new FileEngineResult(fileName, this));
            }

            fileName = "~/Skins/Conferences" + originalFileName;

            if (VirtualPathProvider.FileExists(fileName))
            {
                return(new FileEngineResult(fileName, this));
            }

            return(new FileEngineResult(new [] { fileName }));
        }
Exemple #22
0
        private string GetPageVirtualPathNoCache(DynamicDataRoute route, MetaTable table, string action)
        {
            // The view name defaults to the action
            string viewName = route.ViewName ?? action;

            // First, get the path to the custom page
            string customPageVirtualPath = GetCustomPageVirtualPath(table, viewName);

            if (VirtualPathProvider.FileExists(customPageVirtualPath))
            {
                return(customPageVirtualPath);
            }
            else
            {
                if (table.Scaffold)
                {
                    // If it doesn't exist, try the scaffolded page, but only if scaffolding is enabled on this table
                    return(GetScaffoldPageVirtualPath(table, viewName));
                }
                else
                {
                    // If scaffolding is disabled, null the path so BuildManager doesn't get called.
                    return(null);
                }
            }
        }
        public void TestDiscoverFiles()
        {
            var vpp = new VirtualPathProvider(new string[] { "~/Layout/" });

            var files = vpp.GetFiles();

            Assert.IsTrue(vpp.FileExists("~/Layout/Basic.master"));
        }
Exemple #24
0
 public static Stream TryOpen(this VirtualPathProvider vpp, string virtualPath)
 {
     if (vpp == null)
     {
         throw new ArgumentNullException(nameof(vpp));
     }
     return(vpp.FileExists(virtualPath) ? vpp.GetFile(virtualPath).Open() : null);
 }
 /// <inheritdoc />
 public override bool FileExists(string virtualPath)
 {
     if (this.IsEmbeddedPath(virtualPath))
     {
         return(true);
     }
     return(_previous.FileExists(virtualPath));
 }
Exemple #26
0
        public void TestDiscoverFiles()
        {
            var vpp = new VirtualPathProvider(new string[] { "~/Layout/" });

            var files = vpp.GetFiles();

            Assert.IsTrue(vpp.FileExists("~/Layout/Basic.master"));
        }
        VirtualFile GetVirtualFile(string virtualPath)
        {
            if (!vpp.FileExists(virtualPath))
            {
                return(null);
            }

            return(vpp.GetFile(virtualPath));
        }
Exemple #28
0
        /// <summary>
        /// 创建视图对象
        /// </summary>
        /// <param name="context"></param>
        /// <param name="virtualPath"></param>
        /// <param name="isPartial"></param>
        /// <returns></returns>
        protected IView CreateViewCore(ControllerContext context, string virtualPath, bool isPartial)
        {
            lock ( _providersSync )
            {
                foreach (var provider in ViewProviders)
                {
                    var view = provider.TryCreateView(context, VirtualPathProvider, virtualPath, isPartial);
                    if (view != null)
                    {
                        OnViewCreated(new JumonyViewEventArgs()
                        {
                            View = view, ViewProvider = provider
                        });
                        return(view);
                    }
                }
            }


            {//默认处理策略
                var handlerPath = virtualPath + ".ashx";

                ViewBase view = null;

                if (VirtualPathProvider.FileExists(handlerPath))
                {
                    if (isPartial)
                    {
                        view = CreateHandledPartialView(virtualPath, handlerPath);
                    }
                    else
                    {
                        view = CreateHandledPageView(virtualPath, handlerPath);
                    }
                }


                if (view == null)
                {
                    if (isPartial)
                    {
                        view = new GenericPartialView(virtualPath);
                    }
                    else
                    {
                        view = new GenericPageView(virtualPath);
                    }
                }


                OnViewCreated(new JumonyViewEventArgs()
                {
                    View = view
                });
                return(view);
            }
        }
        private bool IsRoutedRequest(HttpRequest request)
        {
            string path = request.AppRelativeCurrentExecutionFilePath;

            if (path != "~/" && (_virtualPathProvider.FileExists(path) || _virtualPathProvider.DirectoryExists(path)))
            {
                return(false);
            }
            return(true);
        }
Exemple #30
0
        static bool VirtualPathExists(IApplicationHost appHost, string verb, string uri)
        {
            if (appHost.IsHttpHandler(verb, uri))
            {
                return(true);
            }

            VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;

            return(vpp != null && vpp.FileExists("/" + uri));
        }
        public void ProcessRequest(HttpContext context)
        {
            if (File.Exists(context.Request.PhysicalPath))
            {
                var fileModified = File.GetLastWriteTimeUtc(context.Request.PhysicalPath);
                if (CacheUtility.IsUnmodifiedSince(context.Request, fileModified))
                {
                    CacheUtility.NotModified(context.Response);
                }

                N2.Web.CacheUtility.SetValidUntilExpires(context.Response, DateTime.UtcNow);
                context.Response.TransmitFile(context.Request.PhysicalPath);
            }
            else if (vpp.FileExists(context.Request.AppRelativeCurrentExecutionFilePath))
            {
                if (Modified.HasValue && CacheUtility.IsUnmodifiedSince(context.Request, Modified.Value))
                {
                    CacheUtility.NotModified(context.Response);
                }


                byte[] cached = context.Cache["VirtualPathFileHandler:" + context.Request.AppRelativeCurrentExecutionFilePath] as byte[];
                if (cached != null)
                {
                    context.Response.ContentType = GetContentType(context.Request.AppRelativeCurrentExecutionFilePath);
                    context.Response.OutputStream.Write(cached, 0, cached.Length);
                    return;
                }


                var f = vpp.GetFile(context.Request.AppRelativeCurrentExecutionFilePath);
                using (var s = f.Open())
                {
                    byte[] buffer    = new byte[131072];
                    int    readBytes = ReadBlock(s, buffer);
                    if (readBytes <= 0)
                    {
                        return;
                    }

                    N2.Web.CacheUtility.SetValidUntilExpires(context.Response, DateTime.UtcNow);
                    context.Response.ContentType = GetContentType(context.Request.AppRelativeCurrentExecutionFilePath);
                    context.Response.OutputStream.Write(buffer, 0, readBytes);

                    if (readBytes < buffer.Length)
                    {
                        cached = new byte[readBytes];
                        Array.Copy(buffer, cached, readBytes);
                        context.Cache.Add("VirtualPathFileHandler:" + context.Request.AppRelativeCurrentExecutionFilePath, cached, vpp.GetCacheDependency(context.Request.AppRelativeCurrentExecutionFilePath, new[] { context.Request.AppRelativeCurrentExecutionFilePath }, DateTime.UtcNow), DateTime.MaxValue, TimeSpan.FromMinutes(1), System.Web.Caching.CacheItemPriority.BelowNormal, null);
                    }
                    TransferBetweenStreams(buffer, s, context.Response.OutputStream);
                }
            }
        }