MVC Bundle生成的css路径问题

  项目是嵌套在主站的一个子站点,结果用CssRewriteUrlTransform来将相对目录路径改成相对网站根目录路径的时候发现少了虚拟目录的路径。最终解决方案:

 /// <summary>
/// 实现支持虚拟目录的路径转换
/// </summary>
public class CssRewriteUrlTransformWrapper : IItemTransform
{
public string Process(string includedVirtualPath, string input)
{
return new CssRewriteUrlTransform().Process("~" + VirtualPathUtility.ToAbsolute(includedVirtualPath), input);
}
}

  调用的方式:

   bundles.Add(new StyleBundle("~/Content/css").Include("~/media/css/default.css",
"~/media/css/uniform.default.css",
"~/Content/bootstrapValidator.css",
//"~/Content/icheckv2/skins/green.css",
"~/Scripts/sweetAlert2/sweetalert2.min.css",
).Include("~/Content/icheckv2/skins/green.css",new CssRewriteUrlTransformWrapper()) );
BundleTable.EnableOptimizations = true;// ConfigurationManager.AppSettings["Environment"]!="Dev";

  参考地址:CssRewriteUrlTransform with or without virtual directory

上一篇:可视化之AQICN


下一篇:vue组件创建学习总结