简体   繁体   English

asp.net Webforms捆绑和缩小 - 捆绑脚本抛出404

[英]asp.net Webforms Bundling & minification - Bundled script throws 404

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. 我一直在尝试为我现有的asp.net webforms项目实现捆绑和缩小,不幸的是它最终得到了404响应。

Let me first share the steps I have followed. 让我先分享一下我所遵循的步骤。

  1. Installed System.Web.Optimization through nuget. 通过nuget安装System.Web.Optimization

  2. Added BundleConfig class and registered it on Glabal.asax Application_Start event 添加了BundleConfig类并将其注册到Glabal.asax Application_Start事件中

My code to bundle the JS files. 我的代码捆绑JS文件。

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 将以下标记添加到aspx页面
  <asp:PlaceHolder runat="server"> <%: System.Web.Optimization.Scripts.Render("~/bundles/modelJs") %> </asp:PlaceHolder> 
  1. set BundleTable.EnableOptimizations = true; set BundleTable.EnableOptimizations = true; in bundleConfig and the url formed is 在bundleConfig中,形成的url是

http://localhost:9011/bundles/modelJs/?v=xNmmFhbzC1isUARLQne-XoBRkWBWApbnRQX8AGvNxQY1 HTTP://本地主机:9011 /捆绑/ 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. 我还检查了在VS2013 webforms应用程序中添加的示例项目,并且令人惊讶的是,它似乎工作正常。

I have seen many questions with similar problems on SO but was not able to solve it. 我在SO上看到过很多类似问题的问题,但是无法解决。

Well, the solution turns out to be very simple. 嗯,解决方案结果非常简单。 Just added '/' after bundling folder which is modeljs in this case. 刚刚在捆绑文件夹之后添加'/',在这种情况下是modeljs

 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. 不幸的是,我没有在任何可用的源代码中找到这个,所以我最终浪费了很多时间。 :-/ : - /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM