CSS files are not showing on server - ASP.NET MVC Bundles error. 403 - Forbidden: Access is denied

StackOverflow https://stackoverflow.com/questions/22895739

  •  28-06-2023
  •  | 
  •  

Question

My MVC 4 application works fine on my local computer.

However, the CSS files are not working after I publish (are not affecting the layout of the website).

I can see CSS the files are on the server.

When I look at the source code, I can see

<link href="/Content/css?v=fxCdHAOgPDvcROxkMfEwGQggO9uCfzckN3PaN8BOIzI1" rel="stylesheet"/>

where as on my local computer, the source code shows as

<link href="/Content/css/myFile.css" rel="stylesheet"/>
<link href="/Content/css/myFile02.css" rel="stylesheet"/>

So, in the source code view on the server, I clicked on Content/css?v=fxCdHAOgPDvcROxkMfEwGQggO9uCfzckN3PaN8BOIzI1 and the browser took me to a 403 - Forbidden: Access is denied.

I am adding the CSS files with the BunldeConfig.cs class

    public class BundleConfig
    {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/javascript").Include(
                        "~/Scripts/1.9.1.js",
                        "~/Scripts/jTools.js",
                        "~/Scripts/script.js"
                        ));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                "~/Content/Css/website.css", 
                "~/Content/Css/banner.css", 
                "~/Content/Css/reusable.css",
                "~/Content/Css/lists.css",
                "~/Content/Css/tooltip.css",
                "~/Content/Css/overlay.css"
                ));


        }
    }

My question is, assuming this isn't an IT issue with the server (it has been working fine until recently) is there something wrong with my code?

Was it helpful?

Solution

Your problem is that you are using ~/Content/css as a bundle alias in new StyleBundle("~/Content/css"), while this path actually exists.

So when you are requesting <link href="/Content/css?...> you are essentially asking for a directory listing and that is forbidden.

Try using something else, like new StyleBundle("~/Content/styles").

NOTE: If you do use something like ~/Content/styles as an alias you may have issues with relative urls in your .css files. It may seem odd, but you may better use something like ~/Content/Css/someAlias

OTHER TIPS

In the section of <system.web>of your root web.config file , the debug mode is not included. when you publish your application it does not include the debug attribute. So you include the following code:

<compilation debug="true" targetFramework="4.5"> instead of <compilation targetFramework="4.5"> in your web.config file.

For more info You can follow the This Link .

If you actually have any physical folder css inside Content folder this problem occurs.. To resolve it either you remove the physical css folder or rename it to any-other name .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top