Moslem7026
Moslem7026

Reputation: 3338

bundle and minification return 404

  1. Package System.Web.Optimizationhas Been Installed
  2. bundle has been configured as below

    using System.Web.Optimization;
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/Content/themes/base/js").Include("~/Scripts/Site.js"));
            bundles.Add(new StyleBundle("~/Content/themes/base/css").Include("~/Content/Site.css"));
    
        }
    }
    
  3. add this to Layout.cshtml

    @System.Web.Optimization.Scripts.Render("~/Content/themes/base/js")
    @System.Web.Optimization.Styles.Render("~/Content/themes/base/css")
    

css minified succesfully but return 404 error for js file ?

Upvotes: 6

Views: 5556

Answers (2)

Mikael Engver
Mikael Engver

Reputation: 4768

I suddenly received 404 errors on one of my production servers for my sites script bundle resource.

After a bit of searching I found this blogpost that suggest the following solution that should be used in web.config in the section system.webServer that worked great.

<modules runAllManagedModulesForAllRequests="true">
    <remove name="BundleModule" />
    <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>

Upvotes: 6

Colin Bacon
Colin Bacon

Reputation: 15609

Make sure that your virtual path for your bundle Content/themes/base/js does not relate to a real path. Generally we use ~/bundles in our virtual path for this reason.

Example

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/base/js").Include("~/Scripts/Site.js"));
    bundles.Add(new StyleBundle("~/bundles/base/css").Include("~/Content/Site.css"));

}

Upvotes: 8

Related Questions