Bundle doesn’t work when I publish the site

Asked

Viewed 800 times

2

I’m using the BundleConfig.cs in my project to reference the JS and CSS libraries. Below are examples:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
            "~/Content/Scripts/bootstrap/bootstrap.js"));

bundles.Add(new StyleBundle("~/Content/css/font-awesome").Include(
            "~/Content/CSS/base/font-awesome.css"));

To use them, I do it as follows:

@Scripts.Render("~/bundles/bootstrap")
@Styles.Render("~/Content/css/font-awesome")

In the archive BundleConfig.cs, also have the instruction below:

BundleTable.EnableOptimizations = true;

The problem is that when I publish my site on IIS7, the application cannot identify the files and add their reference.

The briefcase bundle is created in the correct way, as image below, but it seems that the site can not recognize them:

inserir a descrição da imagem aqui

I have already done the test to add the settings below on web.config, but without success

<location path="bundles">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

Thank you!

  • The time this happened here, after a lot of effort we found that the problem occurred because my boss merged the Scripts folder when deploying (instead of deleting and pasting the new version). The folders that remained there of residue conflicted with the names of Bundles. It doesn’t seem to be your case, I’m just commenting here for the next ones who consult this question.

2 answers

1

This problem is a bit complex and bizarre because the solution is not obvious. The problem lies in the reference to your CSS.

Here:

bundles.Add(new StyleBundle("~/Content/css/font-awesome").Include(
        "~/Content/CSS/base/font-awesome.css"));

You are forcing the creation of a route on top of a static directory, which confuses the IIS. The preserves were the own team that wrote the mechanism of Bundling. The right one would be to use a route on top of a directory that does not exist to work properly. The full explanation is here.

To solve, just use another route name (or directory, as you wish):

bundles.Add(new StyleBundle("~/BundledStyles/css/font-awesome").Include( // Eu uso assim
        "~/Content/CSS/base/font-awesome.css"));

And why it works on IIS Express?

Because he has fewer route handlers, including the absence of the static handler, which is what causes this confusion.

0

In case anyone still has a problem with that, after getting beaten a lot, I did kind of the opposite of what was said here at the beginning of this post, and it worked.

in my Bundle.config I force, false in Enableoptimizations.

bundles.IgnoreList.Clear();
BundleTable.EnableOptimizations = false;

In Config I left as follows:

  <system.webServer>
    <!--<modules runAllManagedModulesForAllRequests="true" />-->
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="BundleModule" />
      <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
    </modules>

And it worked.

  • There was an excerpt.

  • In Config I left it as follows: <system.webserver> <!-<modules runAllManagedModulesForAllRequests="true" />--> <modules runAllManagedModulesForAllRequests="true"> <remove name="Bundlemodule" /> <add name="Bundlemodule" type="System.Web.Optimization.Bundlemodule" /> </modules>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.