Bundle does not work when I publish the site

2

I'm using BundleConfig.cs in my project to reference the JS and CSS libraries. Here are some 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 the following:

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

In the file BundleConfig.cs , I also have the statement below:

BundleTable.EnableOptimizations = true;

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

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

I'vealreadydonethetesttoaddthesettingsbelowinweb.config,buttonoavail

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

Thank you!

    
asked by anonymous 19.07.2016 / 19:17

1 answer

1

This problem is somewhat complex and bizarre because the solution is not obvious. The problem is 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 IIS. The presepada was from the own team that wrote the mechanism of Bundling . The right thing would be to use a route on top of a directory that does not exist to function properly. The full explanation is here .

To solve, just use another route name (or directory, however you want):

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

And why does it work on IIS Express?

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

    
21.09.2016 / 20:30