How can I dynamically add bundles after Application

I have an asp.net MVC4 web application that uses style bundling for themes. I have a physical themes folder structure like so...

 Themes
     _Base
     Theme1
     Theme2
     ...

Each themes folder has an arbitrary number of LESS files in it. In my BundleConfig.RegisterBundles method, I have some logic that loops through each themes folder and creates a bundle for each. The bundling mechanism from System.Web.Optimization will watch for changes within the files and folders that are in existing bundles and flush the bundles cache, which works fine.

What I need, however, is a way for new theme folders (ie Theme3 ) to be copied into my Themes root folder, and the application to recognize those without having to first restart it. I have tried creating a "dummy" bundle that references all files in every folder...

var changeTracking = new StyleBundle(BUNDLE_ROOT);
changeTracking.Transforms.Clear();
changeTracking.IncludeDirectory(THEME_ROOT, "*.less", true);
changeTracking.Transforms.Add(new LessTransform());
changeTracking.Transforms.Add(new CssMinify());
bundles.Add(changeTracking);

...but that doesn't seem to help. When I make Theme3 , it doesn't trigger another call to BundleConfig.RegisterBundles . I still have to do an IISRESET, recycle the application pool, etc. to get the new theme to be recognized.

Is there any way I can dynamically add bundles after Application_Start has occurred?


This isn't something we explicitly are trying to support, the expectation is that all bundles are registered before the app starts. Otherwise this will cause issues in webfarm scenarios where some of bundles don't exist on all of your servers, which would result in 404s.

The bundle cache dependencies will take care of flushing old responses from the ASP.NET cache, but it would not trigger another call to RegisterBundles, that is called from your global.asax and would only be called during an app recycle like you've mentioned.

链接地址: http://www.djcxy.com/p/69902.html

上一篇: 如何减少div的一部分

下一篇: 我如何在应用程序之后动态添加包