我在IIS中有一个网站,网站下面有几个web应用程序(网站和web应用程序都是mvc web应用程序)。MVC捆绑:如何在儿童webapp中使用家长网站捆绑资源?
网站使用ASP.NET MVC捆绑 -
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/css")
.IncludeDirectory("~/Content/Styles", "*.css", true));
bundles.Add(new ScriptBundle("~/Content/js")
.IncludeDirectory("~/Content/Scripts", "*.js", true));
}
在网站_Layout.cshtml -
@Styles.Render("~/Content/css")
@Script.Render("~/Content/js")
当网站浏览(如mywebsite.com),我可以看到查询字符串附加到那些参考。
<link href="/Content/css?v=asdsf$dfsdfdslkko" rel="stylesheet" />
<script src="/Content/[email protected]"></script>
以及在IIS该网站在我孩子的web应用程序,如果我必须使用相同的捆绑的资源,我可以做(在Web应用程序布局页) -
@Styles.Render("/Content/css")
@Script.Reder("/Content/js")
当web应用程序浏览(例如mywebsite.com/mywebapp),我可以从父网站访问这些资源,但我无法在样式和脚本引用中获得这些querystrings。
<link href="/Content/css" rel="stylesheet" />
<script src="/Content/js></scripts>
唯一的区别是我必须使用开始/
为web应用这是不产生查询字符串的原因。这是一个奇怪的行为。我在浏览webapp时也需要querystring(以避免缓存)。如果我在我的父网站中使用/
而不是~
,querystring会消失(DISGUSTING)。
是否仍然保留查询字符串,即使使用/
来引用捆绑包?任何帮助将不胜感激。 在此先感谢。
为什么要避免在捆绑资源上缓存,为什么? – Hackerman
querystring只有在底层资源被修改时才被修改,如果没有被修改,我们可以从浏览器缓存中获取它们。 –