简体   繁体   中英

JS and CSS are not being loaded. Files seems to be empty

I'm using ASP.NET MVC and my application is hosted in a local IIS. Everything was working fine. However, things start going weird when one of my colleagues downloaded a copy of the project from TFS Server and tried to set it up. CSS and JS are not being loaded.

When I browsed to these links via the page source code, I got empty files. It seems that the files are empty, but they are not.

   <link href="/Content/bootstrap.css" rel="stylesheet"/>
   <script src="/Scripts/modernizr-2.6.2.js"></script>

Here is my bundle configuration.

    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));
               .Include("~/Content/bootstrap.css")
              // ...
    );

Many answers here in SO are suggesting to disable debug via web.config, but I need to debug.

EDIT: It must be related with IIS configuration, because I changed from Local IIS to ISS Express and everything worked fine.

To enable bundling and minification, set the debug value to "false". You can override the Web.config setting with the EnableOptimizations property on the BundleTable class.

<system.web>
    <compilation debug="true" />
    <!-- Lines removed for clarity. -->
</system.web>

Unless EnableOptimizations is true or the debug attribute in the compilation Element in the Web.config file is set to false, files will not be bundled or minified. Additionally, the .min version of files will not be used, the full debug versions will be selected.

public static void RegisterBundles(BundleCollection bundles)
{
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));
               .Include("~/Content/bootstrap.css");

       BundleTable.EnableOptimizations = true;
}

As a temporary solution, I changed from Local IIS to ISS Express and everything was loaded as expected.

Update : I found the solution by enabling Static Content in the IIS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM