ASP.NET MVC Bundle not rendering script files on staging server. It works on development server

前端 未结 8 1562
感动是毒
感动是毒 2020-11-28 05:48

In our ASP.NET MVC 4 web application, our BundleConfig.cs includes the following:

bundles.Add(new ScriptBundle(\"~/bundles/jquery\").Include(
                        


        
相关标签:
8条回答
  • 2020-11-28 06:35

    I used Identity2 then Scripts didn't load for anonymous user then I add this code in webconfig and Sloved.

    <location path="bundles">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>  
    </system.web>
     </location>
    
    0 讨论(0)
  • 2020-11-28 06:36

    Whenever I set debug="off" in my web.config and run my mvc4 application i would end up with ...

    <script src="/bundles/jquery?v=<some long string>"></script>

    in my html code and a JavaScript error

    Expected ';'

    There were 2 ways to get rid of the javascript error

    1. set BundleTable.EnableOptimizations = false in BundleConfig.cs

    OR

    1. I ended up using NuGet Package Manager to update WebGrease.dll. It works fine irrespective if debug= "true" or debug = "false".
    0 讨论(0)
  • 2020-11-28 06:42

    By adding following code of line in bundle to config it works for me

    bundles.IgnoreList.Clear();  
    

    Follow the link for more explanation

    0 讨论(0)
  • 2020-11-28 06:45

    add to your global file this action.

    protected void Application_Start() {
       BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    
    0 讨论(0)
  • 2020-11-28 06:46

    I ran into the same problem, and I'm not sure why, but it turned out to be that the script link generated by Scripts.Render did not have a .js extension. Because it also does not have a Type attribute the browser was just unable to use it (chrome and firefox).

    To resolve this, I changed my bundle configuration to generate compiled files with a js extension, e.g.

                var coreScripts = new ScriptBundle("~/bundles/coreAssets.js")
                .Include("~/scripts/jquery.js");
    
            var coreStyles = new StyleBundle("~/bundles/coreStyles.css")
                .Include("~/css/bootstrap.css");
    

    Notice in new StyleBundle(... instead of saying ~/bundles/someBundle, I am saying ~/bundlers/someBundle.js or ~/bundles/someStyles.css..

    This causes the link generated in the src attribute to have .js or .css on it when optimizations are enabled, as such the browsers know based on the file extension what mime/type to use on the get request and everything works.

    If I take off the extension, everything breaks. That's because @Scripts and @Styles doesn't render all the necessary attributes to understand a src to a file with no extension.

    0 讨论(0)
  • 2020-11-28 06:50

    For me, the fix was to upgrade the version of System.Web.Optimization to 1.1.0.0 When I was at version 1.0.0.0 it would never resolve a .map file in a subdirectory (i.e. correctly minify and bundle scripts in a subdirectory)

    0 讨论(0)
提交回复
热议问题