是否有可能改变 System.Web.Optimization 呈现包的方式?
从:
<script src="/bundles/js/bundlename?v=GMFuN8gzKMcwk5BwaMfgjUlieAXKThyQd8twrVplJ8A1"></script>
对于这样的自定义:
<script src="/bundles/js/v-GMFuN8gzKMcwk5BwaMfgjUlieAXKThyQd8twrVplJ8A1/bundlename"></script>
更新:不理想但小讨厌的解决方法:
public static class BundlesHelper
{
public static IHtmlString RenderScripts(params string[] paths)
{
#if DEBUG
return System.Web.Optimization.Scripts.Render(paths);
#endif
// Get raw string
var rawString = System.Web.Optimization.Scripts.Render(paths).ToHtmlString();
// Get version value
var version = Regex.Match(rawString, @"\?v=([0-9a-zA-Z_-])+").Value;
// Remove old hash
rawString = rawString.Replace(version, "");
// Remove script end tag
rawString = rawString.Replace("</script>", "");
// Get last index of "/"
var index = rawString.LastIndexOf('/');
// Return new string
return new HtmlString(rawString.Insert(index, "/v-" + version.Replace("?v=", "")) + "</script>");
}
}