当前位置: 首页>>代码示例>>C#>>正文


C# VirtualPathProvider.FileExists方法代码示例

本文整理汇总了C#中System.Web.Hosting.VirtualPathProvider.FileExists方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPathProvider.FileExists方法的具体用法?C# VirtualPathProvider.FileExists怎么用?C# VirtualPathProvider.FileExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Hosting.VirtualPathProvider的用法示例。


在下文中一共展示了VirtualPathProvider.FileExists方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadContent

    /// <summary>
    /// 利用指定 VirtualPathProvider 将虚拟路径所指向文件当作静态文件加载。
    /// </summary>
    /// <param name="provider">指定的 VirtualPathProvider</param>
    /// <param name="virtualPath">虚拟路径</param>
    /// <returns>加载结果</returns>
    public HtmlContentResult LoadContent( VirtualPathProvider provider, string virtualPath )
    {

      if ( !VirtualPathUtility.IsAppRelative( virtualPath ) )
        return null;

      if ( !provider.FileExists( virtualPath ) )
        return null;

      var file = provider.GetFile( virtualPath );

      if ( file == null )
        return null;



      var key = provider.GetCacheKey( virtualPath ) ?? "StaticFile_" + virtualPath;

      var content = HttpRuntime.Cache.Get( key ) as string;


      if ( content == null )
      {
        var dependency = HtmlServices.CreateCacheDependency( provider, virtualPath );
        content = LoadContent( file );

        HttpRuntime.Cache.Insert( key, content, dependency );
      }


      return new HtmlContentResult( content, key );
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:38,代码来源:StaticFileContentProvider.cs

示例2: Write

        private void Write(HttpContext context, VirtualPathProvider vpp, string cssPath)
        {
            var mappedPath = context.Server.MapPath(cssPath);
            if(File.Exists(mappedPath))
                context.Response.AddFileDependency(mappedPath);

            var file = vpp.GetFile(cssPath);
            using (var s = file.Open())
            using (var tr = new StreamReader(s))
            {
                while (tr.Peek() >= 0)
                {
                    var line = tr.ReadLine();
                    string importPath = GetImportedPath(context, vpp, cssPath, line);

                    if (string.IsNullOrEmpty(importPath))
                        // process all lines except imports
                        context.Response.Write(Process(line, VirtualPathUtility.GetDirectory(cssPath)));
                    else if (vpp.FileExists(importPath))
                        // recurse into imports and output
                        Write(context, vpp, importPath);
                    else
                        // fallback just write the line
                        context.Response.Write(line);

                    context.Response.Write(Environment.NewLine);
            
                }
            }
        }
开发者ID:JohnsonYuan,项目名称:n2cms,代码行数:30,代码来源:CssCompilerHandler.cs

示例3: ResolveThemedContent

        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);
        }
开发者ID:Biswo,项目名称:n2cms,代码行数:19,代码来源:ThemeExtensions.cs

示例4: ResolveThemedContent

        private static string ResolveThemedContent(HttpContextBase httpContext, VirtualPathProvider vpp, string contentPath)
        {
            string theme = httpContext.GetTheme();
            if (string.IsNullOrEmpty(theme))
                return Url.ToAbsolute(contentPath);

            string themeContentPath = "~/Themes/" + theme + contentPath.TrimStart('~');
            if (!vpp.FileExists(themeContentPath))
                return Url.ToAbsolute(contentPath);

            return Url.ToAbsolute(themeContentPath);
        }
开发者ID:AnonymousRetard,项目名称:n2cms,代码行数:12,代码来源:ThemeExtensions.cs

示例5: FallbackSearch

    /// <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;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:30,代码来源:VirtualPathHelper.cs

示例6: HasAdminPassword

 internal static bool HasAdminPassword(VirtualPathProvider vpp)
 {
     // REVIEW: Do we need to check for content as well?
     return vpp.FileExists(AdminPasswordFile);
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:5,代码来源:AdminSecurity.cs

示例7: RenderDirectory

        private void RenderDirectory(HtmlTextWriter writer, VirtualPathProvider vpp, VirtualDirectory dir)
        {
            RenderCssAttribute(writer, false);
            writer.RenderBeginTag("ul");

            var dirpath = VirtualPathUtility.ToAppRelative(dir.VirtualPath);
            var pagedir = VirtualPathUtility.GetDirectory(Page.AppRelativeVirtualPath);
            var rootpath = VirtualPathUtility.AppendTrailingSlash(RootPath);

            // Render root directory
            foreach (var vf in dir.Children.Cast<VirtualFileBase>().OrderBy(f => f.Name))
            {
                var filepath = VirtualPathUtility.ToAppRelative(vf.VirtualPath);
                var filedir = VirtualPathUtility.GetDirectory(filepath);
                var filename = VirtualPathUtility.GetFileName(filepath);

                var isinpath = pagedir.StartsWith(filepath);

                if (vf.IsDirectory)
                {
                    filepath = VirtualPathUtility.Combine(filepath, "00_index.aspx");

                    if (!vpp.FileExists(filepath))
                    {
                        // Skip directory, if there's no index file
                        continue;
                    }
                }
                else if (comparer.Compare(dirpath, rootpath) != 0 &&
                         comparer.Compare(filename, "00_index.aspx") == 0 ||
                         comparer.Compare(filename, "Default.aspx") == 0 ||
                         comparer.Compare(VirtualPathUtility.GetExtension(filepath), ".aspx") != 0)
                {
                    // Skip index file and default.aspx in root or non aspx files
                    continue;
                }

                var isselected = comparer.Compare(filepath, Page.AppRelativeVirtualPath) == 0;
                var isinroot = comparer.Compare(filedir, rootpath) == 0;
                var title = GetPageTitle(vpp.GetFile(filepath));

                // Apply css to <li>
                RenderCssAttribute(writer, isselected);
                writer.RenderBeginTag("li");

                // Apply css to <a>
                RenderCssAttribute(writer, isselected);
                writer.AddAttribute("href", VirtualPathUtility.MakeRelative(Page.AppRelativeVirtualPath, filepath));
                writer.RenderBeginTag("a");
                writer.Write(title);
                writer.RenderEndTag();

                writer.RenderEndTag();

                // Render children, if
                //      - it is the current page
                //      - the current page is under this directory
                if (vf.IsDirectory && (isselected || isinpath || (isinroot && ExpandRootLevel)))
                {
                    RenderDirectory(writer, vpp, (VirtualDirectory)vf);
                }
            }

            writer.RenderEndTag();
        }
开发者ID:skyquery,项目名称:graywulf,代码行数:65,代码来源:SiteMap.cs

示例8: GetImportedPath

        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;
        }
开发者ID:Jobu,项目名称:n2cms,代码行数:20,代码来源:CssCompilerHandler.cs

示例9: FallbackSearch

        /// <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;
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:33,代码来源:ViewHandlerProvider.cs


注:本文中的System.Web.Hosting.VirtualPathProvider.FileExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。