I'm trying to use bundle minification for some .css and .js files. My bundle config is the following:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Modernizr").Include(
"~/Scripts/modernizr.js"
));
bundles.Add(new StyleBundle("~/TemplateContent").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-responsive.css",
"~/Content/prettyPhoto.css",
"~/Content/prettify.css",
"~/Content/flexslider.css",
"~/Content/iview.css",
"~/Content/style.css",
"~/Content/default.css"
));
bundles.Add(new StyleBundle("~/AppContent").Include(
"~/Content/bootstrap-tablesorter.css",
"~/Content/animate.css",
"~/Content/font-awesome.css",
"~/Content/jcarousel.css",
"~/Conten/overwrite.css",
"~/Content/sequence.css",
"~/Content/sequence.ie.css",
//more styles
));
bundles.Add(new ScriptBundle("~/TemplateScripts").Include(
"~/Scripts/modernizr-*",
"~/Scripts/jquery.js",
"~/Scripts/raphael.js",
"~/Scripts/jquery.easing.1.3.js",
"~/Scripts/bootstrap.js",
"~/Scripts/google-code-prettify/prettify.js",
"~/Scripts/jquery.elastislide.js",
"~/Scripts/jquery.tweet.js",
"~/Scripts/jquery.prettyPhoto.js",
"~/Scripts/jquery.flexslider.js",
"~/Scripts/iview.js",
"~/Scripts/jquery-hover-effect.js",
"~/Scripts/animate.js",
"~/Scripts/custom.js"
));
bundles.Add(new ScriptBundle("~/AppScripts").Include(
"~/Scripts/jquery.ticker.js",
"~/Scripts/jquery.contenthover.js",
"~/Scripts/jquery-ui-1.10.3.js",
"~/Scripts/datetimepicker.js",
"~/Scripts/jquery.metadata.js",
//more scripts
));
BundleTable.EnableOptimizations = true;
}
The problem happens when I publish the app to a server (godaddy shared web hosting), I do get a minified output, but I get 403 errors on those outputs.
If I set
BundleTable.EnableOptimizations = false;
The files are not minified but the page has the correct behavior.
Turns out it was ASP.NET form authentication. As according to this, the name of the bundle should not be an existing directory. And well, forms authentication denies access to those directories that are not allowed int the web.config.
I did not know that the bundles create their own directory, so I basically added the location tag for those directories (even though they are not physically in the solution).
So basically...
For all of the previous bundles names, I added "~/bundles/" and then created the following location tag in the web.config:
<location path="bundles">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>