0
votes

I am trying to get ASP.NET Bundling to change the way it generates paths for JS/CSS bundles. If my site is hosted on http://example.com/myapp and i use Scripts.Render("~/bundles/js") and Styles.Render("~/bundles/css"), this is what i get:

<script src="/myapp/bundles/js?v=RYQkGlZ5kEreOyiFPLgJ2SkEJtBEjiJQ6NeuVTYwXMY1"></script>
<link href="/myapp/css?v=1FC5SbQ1-E0J4ZXC1coG1W09-2uMUsJx0S1y_amIU3U1" rel="stylesheet"/>

Instead, if through some DNS magic we can enable the user to use the URL http://myapp - although it's still hosted at http://example.com/myapp - I would like the script/style bundles to render URLs like this:

<script src="bundles/js?v=RYQkGlZ5kEreOyiFPLgJ2SkEJtBEjiJQ6NeuVTYwXMY1"></script>
<link href="bundles/css?v=1FC5SbQ1-E0J4ZXC1coG1W09-2uMUsJx0S1y_amIU3U1" rel="stylesheet"/>

Is there a workaround for this? I don't think that Scripts.RenderFormat or Styles.RenderFormat will help with this.

1
Quick answer, poking through the System.Web.Optimizations assembly, it seems like it's pretty hard coded. Unless you want to reinvent the wheel, I think the application relative path is required. There could be something I'm not seeing though.Steven V

1 Answers

0
votes

The root of the problem was that I needed to configure the app to be at the root of my web site.

However, the DNS magic (an F5 load balancer) helped in this case... and our F5 wizard was able to do all the URL re-routing / re-writing for requests so that even though the app is not at the root, the requests get to the correct place.