Bundling with MVC4 not working after I publish to azure

前端 未结 9 2202
闹比i
闹比i 2021-02-08 14:52

Hi I am trying to bundle my scripts for my application. My debug is working and if I publish with the Web.debug every thing works fine. But when I publish with the Web.releas my

相关标签:
9条回答
  • 2021-02-08 15:15

    In my case, the virtual path of my bundle contains the . character. Something like :

    bundles.Add(new ScriptBundle("~/bundles/jquery.loadTemplate").Include(
                "~/Scripts/jquery.loadTemplate/*.js");
    

    I changed the dots by hyphens :

    bundles.Add(new ScriptBundle("~/bundles/jquery-loadTemplate").Include(
                "~/Scripts/jquery-loadTemplate/*.js");
    

    And everything works like a charm.

    I'm still not sure why it worked on my local machine but not on Azure...

    0 讨论(0)
  • 2021-02-08 15:16

    In BundleConfig.cs I had the following:

            bundles.Add(new StyleBundle("~/Content/css").Include(
                "~/Content/css/bootstrap.css",
                "~/Content/css/bootstrap-responsive.css",
                "~/Content/css/site.css"));
    

    I really actually had to use:

    bundles.Add(new StyleBundle("~/Styles/css").Include(
                "~/Content/css/bootstrap.css",
                "~/Content/css/bootstrap-responsive.css",
                "~/Content/css/site.css"));
    

    I also had to update the reference to my CSS Style bundle in _Layout.cshtml

    @Styles.Render("~/Styles/css")
    

    I found this answer here: http://thebeardeveloper.blogspot.com.au/2013/02/403-forbidden-for-css-bundles-in-asp.html

    0 讨论(0)
  • 2021-02-08 15:17

    I had the same problem, but none of the above solutions worked for me.

    The problem is, I had bundling like this:

    @Styles.Render("~/Content/css")
    
    bundles.Add(new StyleBundle("~/Content/css").Include(
        "~/Content/bootstrap.css",
        "~/Content/justified-nav.css",
        "~/Content/site.css"));
    

    But, ~/Content/css is also a directory - which broke when deploying to Azure. I fixed this by changing ~/Content/css to ~/Content/mastercss in both locations

    0 讨论(0)
  • 2021-02-08 15:22

    Small mistakes kill me, I was bundling my css as a script bundle not a style bundle.

    I have done a lot to try fix this including setting up source control and build configurations. My project went from being set up to use git to tfs and everything.

    0 讨论(0)
  • 2021-02-08 15:23

    Let's do some grave digging. Today I started fiddeling around with Azure and promptly ran into a similar problem.

    the style bundle was defined like this:

    bundles.Add(new StyleBundle("~/Styles/css").Include(
                      "~/Content/bootstrap.superhero.css",
                      "~/Content/site.css"));
    

    But no css was being rendered. After almost opening up a second question I realized, that the file bootstrap.superhero.css was greyed out in the solution explorer. What was working locally in Visual Studio, was failing in Azure, because the file was not yet implemented in the project.

    Tl;dr: Right-click the Css file and then "Include in project"

    0 讨论(0)
  • 2021-02-08 15:32

    As one of the answers mentioned, I have fought this a few hours, my problem was also that I had a folder called scripts, so I changed the name of the script from (this is from my index view)

    @Scripts.Render("~/Scripts/CircleStats") //this is also a folder in my project, which I think is the problem for azure
    

    to

    @Scripts.Render("~/bundles/CircleStats")
    

    And it's working, hopefully this will help someone

    https://forums.asp.net/t/1810635.aspx?403+Access+denied+when+using+Bundling

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