1

I've got an ASP.NET web forms application, running on .NET 4.5 using the new Bundling and Minification features from the Microsoft.AspNet.Web.Optimization package.

So far it's a very simple setup just with a single bundle.

BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/send").Include(
        "~/scripts/GrowingInput.js", 
        "~/scripts/textboxlist/TextboxList.js",
        "~/scripts/textboxlist/TextboxList.Livesearch.js",
        "~/scripts/combobox/ui.combobox.js",
        "~/scripts/jquery-ui-timepicker.js",
        "~/scripts/msp.send.js"));
}

Global.asax

protected void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

Send.aspx

<%: Scripts.Render("/bundles/send") %>

This is always rendered in a web browser as <script src="/bundles/send"></script> ignoring whether debug is set to true or false in web.config.

I've tried adding BundleTable.EnableOptimizations = false; to BundleConfig.cs to force bundling off but this makes no difference.

Looking to get the following working like it does in MVC sites (Microsoft documentation seems to suggest web forms should be the same).

  1. Get bundling to turn on/off with the debug flag
  2. Append the cache-busting ?v=xxx querystring for versioning.
4

1 回答 1

7

Bundles paths must start with ~, but the Scripts.Render method is not limited to bundles, so it just treats the url as a local resource, (it uses BundleTable.Bundles.GetBundleFor(path) to determine if the url is a bundle)

You just need to add a ~ like so for this to work: <%: Scripts.Render("~/bundles/send") %>

于 2012-09-27T22:39:02.993 回答