I was so excited to get the new MVC4 Bundling feature into my current MVC3 projects, I didn't want to wait for the release of MVC4. Instead, I searched the web to find a compromise to this, and I found this post:
Using MVC4 Minification and Bundling in MVC3
As I went through the suggested solution however, I encountered two problems:
1. Bundling LESS / DotLess CSS issues.
2. Security issues once deployed, resolving the new bundling URL-s.
The first problem - MVC4 Bundling would trigger prior to DotLess processing, and complain about DotLess syntax, so I had to skip DotLess CSS, bundling only regular CSS for now. But please, somebody, what is the way to solve this type of conflict?
The second problem was more serious, as my hosting (Latest GoDaddy with IIS7 + SQL2008, etc) didn't like the new bundling stuff, saying that the new bundling URL-s (ones with bundling hash-code appended to them) cannot be accessed. I wonder though, if it
is just my implementation or if it is a bigger issue with deploying MVC4 bundling stuff?
Any help much appreciated!
UPDATE
Just to clarify, I get the second error only for CSS, not for JavaScript. In my example the MVC4 Bundling generates the following HTML:
A little clarification on the issue with bundle URL-s. It only happens for CSS bundles, not for JavaScript ones. In my example I get the following generated by MVC4 bundling:
2. Security issues once deployed, resolving the new bundling URL-s.
Try to find the Stack-Trace if Possible. Just install this nuget package
MonitorAspNetApplication, build the application. Navigate your page. Then, navigate to /Monitoring.aspx.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Just went through that link, and the problem it describes is a little different. Plus, the major one for me was in security, i.e. for some reasons my hosting provider returns a No-Access to the bundled css link, even though it does permit the same for Java
Script. Strange. I described it in the other post also.
VitalyT
Member
2 Points
16 Posts
Using MVC4 bundling in MVC3
May 04, 2012 07:03 AM|LINK
Hi All,
I was so excited to get the new MVC4 Bundling feature into my current MVC3 projects, I didn't want to wait for the release of MVC4. Instead, I searched the web to find a compromise to this, and I found this post: Using MVC4 Minification and Bundling in MVC3
As I went through the suggested solution however, I encountered two problems:
1. Bundling LESS / DotLess CSS issues.
2. Security issues once deployed, resolving the new bundling URL-s.
The first problem - MVC4 Bundling would trigger prior to DotLess processing, and complain about DotLess syntax, so I had to skip DotLess CSS, bundling only regular CSS for now. But please, somebody, what is the way to solve this type of conflict?
The second problem was more serious, as my hosting (Latest GoDaddy with IIS7 + SQL2008, etc) didn't like the new bundling stuff, saying that the new bundling URL-s (ones with bundling hash-code appended to them) cannot be accessed. I wonder though, if it is just my implementation or if it is a bigger issue with deploying MVC4 bundling stuff?
Any help much appreciated!
UPDATE
Just to clarify, I get the second error only for CSS, not for JavaScript. In my example the MVC4 Bundling generates the following HTML:
protected void Application_Start() { // some initial code BundleTable.Bundles.Add(CreateCssBundle()); BundleTable.Bundles.Add(CreateJsBundle()); } private Bundle CreateJsBundle() { Bundle bundle = new Bundle("~/Scripts/js", new JsMinify()); bundle.AddFile("~/Scripts/jquery-1.7.2.js"); bundle.AddFile("~/Scripts/jquery.unobtrusive-ajax.js"); bundle.AddFile("~/Scripts/jquery.fancybox.pack.js"); bundle.AddFile("~/Scripts/jquery.fancybox-buttons.js"); bundle.AddFile("~/Scripts/jquery.fancybox-thumbs.js"); bundle.AddFile("~/Scripts/IrishTours.js"); return bundle; } private Bundle CreateCssBundle() { Bundle bundle = new Bundle("~/Content/css"); bundle.AddFile("~/Content/jquery.fancybox.css"); bundle.AddFile("~/Content/jquery.fancybox-buttons.css"); bundle.AddFile("~/Content/jquery.fancybox-thumbs.css"); return bundle; }VitalyT
Member
2 Points
16 Posts
Re: Using MVC4 bundling in MVC3
May 04, 2012 08:42 AM|LINK
Nobody so far? :)
A little clarification on the issue with bundle URL-s. It only happens for CSS bundles, not for JavaScript ones. In my example I get the following generated by MVC4 bundling:
<link rel="stylesheet" href="/Content/css?v=8vTpdQD5EQRQ7pvFwg8L2pL5AGe6WWbmqQ9gmiyJ1so1" type="text/css" />
<script type="text/javascript" src="/Scripts/js?v=2pHMclbM9W-WfnW8mwl_lrNwPJv1u8JxwfUeleH8JwM1"></script>
When I click the second link (JavaScript), it works perfectly, but when I click the first one - I get "Incorrect URL" problem returned by the server.
And the way I set up the bundles is shown below:
protected void Application_Start() { // Some initial code here BundleTable.Bundles.Add(CreateCssBundle()); BundleTable.Bundles.Add(CreateJsBundle()); } private Bundle CreateJsBundle() { Bundle bundle = new Bundle("~/Scripts/js", new JsMinify()); bundle.AddFile("~/Scripts/jquery-1.7.2.js"); bundle.AddFile("~/Scripts/jquery.unobtrusive-ajax.js"); bundle.AddFile("~/Scripts/jquery.fancybox.pack.js"); bundle.AddFile("~/Scripts/jquery.fancybox-buttons.js"); bundle.AddFile("~/Scripts/jquery.fancybox-thumbs.js"); bundle.AddFile("~/Scripts/IrishTours.js"); return bundle; } private Bundle CreateCssBundle() { Bundle bundle = new Bundle("~/Content/css"); bundle.AddFile("~/Content/jquery.fancybox.css"); bundle.AddFile("~/Content/jquery.fancybox-buttons.css"); bundle.AddFile("~/Content/jquery.fancybox-thumbs.css"); return bundle; }By the way, I do not use CssMinify, because I already use LESS for all my CSS.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Using MVC4 bundling in MVC3
May 06, 2012 10:51 AM|LINK
You can eaily create a LESS minify.
Try to find the Stack-Trace if Possible. Just install this nuget package MonitorAspNetApplication, build the application. Navigate your page. Then, navigate to /Monitoring.aspx.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
VitalyT
Member
2 Points
16 Posts
Re: Using MVC4 bundling in MVC3
May 06, 2012 11:04 AM|LINK
Thank you, although I do not know what to make of "easily create a LESS minify". Could you, please, expand on this?
I will try the second thingie though.
After this post I made another one, digesting all the problems I had with MVC4 Bundling here: MVC4 Bundling Problems
- also unanswered :|
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Using MVC4 bundling in MVC3
May 06, 2012 11:07 AM|LINK
http://stackoverflow.com/questions/9593254/mvc4-less-bundle-import-directory
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
VitalyT
Member
2 Points
16 Posts
Re: Using MVC4 bundling in MVC3
May 06, 2012 11:13 AM|LINK
Just went through that link, and the problem it describes is a little different. Plus, the major one for me was in security, i.e. for some reasons my hosting provider returns a No-Access to the bundled css link, even though it does permit the same for Java Script. Strange. I described it in the other post also.