Developer forum

Forum » Development » Microsoft Optimization Framework into Dynamicweb. 404 Error.

Microsoft Optimization Framework into Dynamicweb. 404 Error.

Jeppe Jakobsen
Reply

Hi everyone.

I'm trying to implement bundling and minification (http://www.asp.net/mvc/overview/performance/bundling-and-minification), in a dynamicweb custom application.

So far i've done as you would usually do, by adding the Microsoft Asp.Net Web Optimization NuGet package, and creating a BundleConfig.cs file in the custom application. I then added a js file to a bundle like so:

        public static void RegisterBundles(BundleCollection bundles)
        {
            BundleTable.EnableOptimizations = true; // For debugging purposes.
            bundles.Add(new ScriptBundle("~/bundles/plugins/base").Include("~/Files/Templates/Designs/ExampleDesign/js/jquery-2.1.4.min.js"));
        }

then in Global.asax:

        public void Application_Start(object sender, EventArgs e)
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Fires when the application is started
            Dynamicweb.Frontend.GlobalAsaxHandler.Application_Start(sender, e);
        }

In my master.cshtml i've put a reference to "@using System.Web.Optimization" and added the following line:

@Scripts.Render("~/bundles/plugins/base")

which, when inspecting the element, has rendered something like this:

<script src="/bundles/plugins/base?v=76AIGLyY_agf8nmHAUeHF5fo0HxMeiQhRw6ATlkJEeQ1"></script>

Because it displays a value token, i can only assume that it found the js file and created the bundle, which the Scripts.Render found and displayed the url for. The request then results in an error, which is a "Failed to load the resource: the server responded with a status of 404 (Not Found)". This is my problem.

My general experience using this this framework is that it is pretty much "plug-and-play", but dynamicweb adds an extra layer that, with my limited experience using dynamicweb, can't seem to quite wrap my head around. I've been trying to solve the problem by trying some of the common solutions suggested by a simple search, but with no luck. 

Best Regards, Jeppe


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Jeppe

Dynamicweb configures and enables MVC in the call to GlobalAsaxHandler.Application_Start, so try moving BundleConfig.RegisterBundles(BundleTable.Bundles); after that line of code and see if that helps.

BR Nicolai

 
Jeppe Jakobsen
Reply

Sorry, i already tried that suggestion, but it did not solve it. (And i just retried it.)

 
Klavs Martens
Reply

Hi Jeppe

Did you include the bundle module in web.config?

<system.webServer>
  <modules>
    <add name="BundleModule" type="System.Web.Optimization.BundleModule" />
  </modules>
</system.webServer>

Klavs

 

 

 
Jeppe Jakobsen
Reply

Yes, this was the suggestion that popped up when i tried searching for a solution in google, but it did not change the result.

 
Klavs Martens
Reply
This post has been marked as an answer

If it's Dynamicweb thats messing things up, you can try to bypass it by adding this as the first line in

Applicatiom_AuthenticateRequest, maybe also Application_BeginRequest method in Global.asax.vb

If HttpContext.Current.Request.Url.AbsolutePath.ToLower.Contains("bundles/plugins") Then Return

 

Klavs

Votes for this answer: 1
 
Jeppe Jakobsen
Reply

That did it, thank you!

Knowing this, does a more elegant way of solving it exist? As it feels like this solution is abit dodgy.

 
Klavs Martens
Reply

Not at the moment. We do the same inside Application_AuthenticateRequest with mvc/webapi routes, and it works fine.

 

You must be logged in to post in the forum