Mvc bundle throwing 403 forbidden error in Azure

less than a minute read

A while back when I was first releasing my blog, I came across an error that had not troubled me during local testing.

I had created a couple of new bundles to support Prettify in my BundleConfig.cs:

        bundles.Add(new ScriptBundle("~/Content/prettify")
                            .Include("~/Scripts/Prettify/prettify.js"));

        bundles.Add(new StyleBundle("~/Content/prettify")
                            .Include("~/Content/Prettify/prettify.css"));

After a bit of digging the cause was due the fact that the folder /Content/prettify already exists in my application meaning that IIS was handling the request and not MVC. Once this was realized, the fix was simple. I simply changed the virtualPath parameter values to not include existing folders.

        bundles.Add(new StyleBundle("~/bundles/css/prettify")
                            .Include("~/Content/Prettify/prettify.css"));

        bundles.Add(new ScriptBundle("~/bundles/js/prettify")
                            .Include("~/Scripts/Prettify/prettify.js"));

This was a simple fix once the cause was identified (from stackoverflow). I hope this is useful to anyone else out there with the same issue.

In order to be sure not to run into this error in the future I decided to use a simple prefix for my all bundles, namely bundles/css for styling and bundles/js for (yes, you've guessed it) script bundles.