Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 236
MyDaftQuestions Avatar asked Apr 06 '14 15:04

MyDaftQuestions


People also ask

Why do I get Error 403 Forbidden?

The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it. This status is similar to 401 , but for the 403 Forbidden status code re-authenticating makes no difference.


2 Answers

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

like image 198
lalibi Avatar answered Oct 30 '22 20:10

lalibi


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 .

like image 34
Mahbub Avatar answered Oct 30 '22 22:10

Mahbub