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


C# UrlHelper.AssetPath方法代码示例

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


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

示例1: GetAssetSources

    public IEnumerable<string> GetAssetSources(AssetType type, PageModel pageModel, UrlHelper helper)
    {
      //load items not in any group or delivered by CDN
      foreach (Asset asset in GetNonGroupedAssets(pageModel.Assets, type))
      {
        if (Settings.Default.UseCDN && GetCdnUrl(asset.Name) != null)
          yield return GetCdnUrl(asset.Name);
        else yield return helper.AssetPath(asset.AssetType, asset.Name);
      }

      var groups = pageModel.Assets.Select(a => a.Group).Distinct().ToArray();
      var grouped = GetGroupedAssets(pageModel.Assets, groups, type);
      if (AssetGroupMode == AssetGroupMode.Disabled)
      {
        foreach (string s in grouped.Select(a => helper.AssetPath(a.AssetType, a.Name)))
          yield return s;
      }
      else //load local via combination
      {
        if (grouped.Count > 0)
        {
          foreach (string group in groups)
          {
            //the following method will load and cache the combined script for later
            var version = GetGroupCombined(type, group, helper).Md5;
            //add versioning querystring for future updates overridding expires
            yield return helper.RouteUrl("AssetGroup" + type.ToString(), new { group = group, v = version });
          }
        }
      }
    }
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:31,代码来源:AssetService.cs

示例2: GetGroupCombined

    public GroupCombinedAsset GetGroupCombined(AssetType type, string group, UrlHelper helper)
    {
      string key = string.Format("{0} - {1}", type, group);

      //first try to get from cache
      GroupCombinedAsset combined = helper.RequestContext.HttpContext.Cache[key] as GroupCombinedAsset;
      if (combined != null) return combined;

      if (type != AssetType.Js && type != AssetType.Css)
        throw new ArgumentException("Can't group for the given type.", "type");

      AggregateCacheDependency cacheDep = new AggregateCacheDependency();

      IContainer container = (IContainer)helper.RequestContext.HttpContext.Application["Container"];
      var assets = GetGroupedAssets(
        //global
        Assets
        //pages
        .Concat(container.GetAllInstances<IPage>().SelectMany(p => p.Assets))
        //widgets
        .Concat(container.GetAllInstances<IWidget>().SelectMany(w => w.Assets)).ToList(), new[] { group }, type);

      StringBuilder sb = new StringBuilder();
      foreach (Asset a in assets)
      {
        //add helpful debugging info when not going to minify
        string path = helper.AssetPath(a.AssetType, a.Name);
        if (AssetGroupMode != AssetGroupMode.CombineAndMinify)
        {
          sb.Append(Environment.NewLine);
          sb.Append(Environment.NewLine);
          sb.AppendFormat("/* asset: {0} */", path);
          sb.Append(Environment.NewLine);
        }
        path = helper.RequestContext.HttpContext.Server.MapPath(path);
        try
        {
          sb.Append(File.ReadAllText(path));
          cacheDep.Add(new CacheDependency(path));
          sb.Append(Environment.NewLine);
        }
        catch (FileNotFoundException ex)
        {
          LogService.Warn(ex.Message);
        }
      }

      string content = string.Empty;
      if (sb.Length > 0)
      {        
          if (type == AssetType.Css)
              content = AssetGroupMode == AssetGroupMode.CombineAndMinify ?
                Minify(type, sb.ToString()) : sb.ToString();
          else
              content = AssetGroupMode == AssetGroupMode.CombineAndMinify ?
                Minify(type, sb.ToString()) : sb.ToString();
      }

      combined = new GroupCombinedAsset()
      {
        Content = content,
        Group = group,
        Md5 = AtomSite.Utils.SecurityHelper.HashIt(content, "MD5"),
        LastModified = cacheDep.UtcLastModified.ToLocalTime()
      };

      helper.RequestContext.HttpContext.Cache.Add(key, combined, cacheDep, Cache.NoAbsoluteExpiration,
        Cache.NoSlidingExpiration, CacheItemPriority.AboveNormal, null);
      return combined;
    }
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:70,代码来源:AssetService.cs


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