Script Bundling in WebForms with Virtual Directories

天涯浪子 提交于 2019-12-14 03:57:14

问题


We have a separate "Framework" project for shared controls, javascript, etc. that is used by this and other projects. The Framework project is included in our solution, and we made a virtual directory for it with IIS so we can still make relative links to files with ~/Framework.

So, we want to begin using the new Web Optimization bundles for scripts and styles. Everything is working fine, but we are having issues when attempting to use bundling with JS files in the virtual directory. When debug="false" is set, the files are correctly bundled & minified. When debug="true" is set it does not include any of the files!

Clearly it has access to the files since it can bundle & minify them together. Is there a way to make this work?


Here's what I have in App_Start/BundleConfig.vb

    Public Shared Sub RegisterBundles(bundles As BundleCollection)
        Dim mainBundle = New ScriptBundle("~/bundles/main")
        mainBundle.Orderer = New AsIsBundleOrderer()
        mainBundle.Include("~/Framework/Javascript/Main/Library.jQuery.js")
        mainBundle.Include("~/Framework/Javascript/Main/Library.jQuery.ui.js")
        'snip....
        mainBundle.Include("~/Framework/Javascript/Main/CP.Base.js")

        bundles.Add(mainBundle)
    End Sub

Here's what I have in my MasterPage:

    <%: System.Web.Optimization.Scripts.Render("~/bundles/main") %>

回答1:


create a class under App_Code folder in your project and add this code in to the class

Public Shared Sub RegisterBundles(bundles As BundleCollection)
    Dim mainBundle = New ScriptBundle("~/bundles/main")
    mainBundle.Orderer = New DefaultBundleOrderer()
    mainBundle.Include("~/HTML5Components/adc.js")
    bundles.Add(mainBundle)
End Sub

after that open Global.asax

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    BundleConfig.RegisterBundles(BundleTable.Bundles)         
End Sub


来源:https://stackoverflow.com/questions/17998859/script-bundling-in-webforms-with-virtual-directories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!