Bundled css link gets a 404 error

前端 未结 6 970
不知归路
不知归路 2020-12-09 16:24

I am trying to get bundling to work in ASP.NET MVC 4. I am getting a 404 error from the link generated for the bundled CSS. I have done the following:

  1. Ins

相关标签:
6条回答
  • 2020-12-09 16:58

    It seems that you have missed the step in which you apply your configuration by calling RegisterBundles in Application_Start:

    protected void Application_Start()
    {
        ...
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        ...
    }
    

    Usually in cases where the BundleConfig class is already there (either as a part of the project template or created by NuGet package during the installation) this call is also already present - this is why many tutorials are implicit about it.

    You should also be aware that the BundleConfig class is there for separation of concerns and in order to keep the Application_Start clean. In simple cases nothing prevents you from registering bundles directly in Application_Start:

    protected void Application_Start()
    {
        ...
        BundleTable.Bundles.Add(new StyleBundle("~/bundles/styles/cvi").Include("~/mainstyles.css"));
    
        ...
    }
    
    0 讨论(0)
  • 2020-12-09 16:59

    I had the same problem that my script bundle suddenly responded with 404. I a solution similar to @fiat answer that I found on this blogpost.

    The solution was to remove and add the BundleModule in the modules part section of the system.webServer section.

    <modules runAllManagedModulesForAllRequests="true">
        <remove name="BundleModule" />
        <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
    </modules>
    
    0 讨论(0)
  • 2020-12-09 17:04

    If you have this error while using Umbraco don't forget to add also this line to your web.config:

    <add key="Umbraco.Core.ReservedUrls" value="~/bundles/" />
    
    0 讨论(0)
  • 2020-12-09 17:06

    Found this question via google results, but the problem in my case was Windows 2008 needed this in web.config to work when compilation debug=false.

    <system.webServer>
      <modules>
        <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
      </modules>
    </system.webServer>
    

    It worked fine on Win7 dev machine without this.

    0 讨论(0)
  • 2020-12-09 17:10

    All my bundles names starting with "~/bundles/..." were not found in my WebAPI. Adding the line to my RouteConfig.cs class

        routeCollection.Ignore("bundles/{*catch}");
    

    fixed my issue.

    0 讨论(0)
  • 2020-12-09 17:17

    I hade same problem (in ASP.Net webform), i resolved my issue with Ignore "bundles/" route in Global.asax :

    routeCollection.Ignore("bundles/{*catch}");
    
    0 讨论(0)
提交回复
热议问题