5

I have been trying to implement bundling and minification for my existing asp.net webforms project and unfortunately it is ending up with 404 responses.

Let me first share the steps I have followed.

  1. Installed System.Web.Optimization through nuget.

  2. Added BundleConfig class and registered it on Glabal.asax Application_Start event

My code to bundle the JS files.

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/modelJs").Include( 
    "~/src/model.js", 
    "~/src/calender.js", 
    "~/src/common.js", 
    "~/src/insurance.js")); 

...

  1. Added following markup to aspx page
 <asp:PlaceHolder runat="server"> 
    <%: System.Web.Optimization.Scripts.Render("~/bundles/modelJs") %> 
    </asp:PlaceHolder>
  1. set BundleTable.EnableOptimizations = true; in bundleConfig and the url formed is

http://localhost:9011/bundles/modelJs/?v=xNmmFhbzC1isUARLQne-XoBRkWBWApbnRQX8AGvNxQY1

I have also checked the sample project which gets added in VS2013 webforms application and surprisingly, it seems to be working fine.

I have seen many questions with similar problems on SO but was not able to solve it.

Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116
  • As discussed in chat, the generated URL looks wrong, with a slash between "modelJs" and the query string. You confirmed there were no rewrite rules in place, the same issue exists without the wrapping the Render(), and that navigating to the /bundles/modelJs URL directly doesn't display anything. I'm still stumped! – Squiggle Feb 17 '16 at 10:14

1 Answers1

5

Well, the solution turns out to be very simple. Just added '/' after bundling folder which is modeljs in this case.

 bundles.Add(new ScriptBundle("~/bundles/modelJs/").Include( 

Unfortunately, I didn't find this in any available source codes so I ended up wasting a lot of time. :-/

Sangram Nandkhile
  • 17,634
  • 19
  • 82
  • 116