ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误)

web开发作者:dayu日期:10天前点击:5

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 onContent/css?v=fxCdHAOgPDvcROxkMfEwGQggO9uCfzckN3PaN8BOIzI1and 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?

StackOverFlow论坛上专家的回答:

Your problem is that you are using~/Content/cssas a bundle alias innew 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, likenew StyleBundle("~/Content/styles").

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

也就是说构造StyleBundle和ScriptBundle时定义的虚拟路径不能是服务器上真实存在的物理路径,同时上面这位专家还提到StyleBundle的虚拟路径最好也不要使用~/Content/styles,因为这可能会使.css文件的访问出现问题,对于StyleBundle最好用~/Content/Css/someAlias来作为虚拟路径。

StackOverFlow原文地址

ASP.NET MVC4中的bundles特性引发服务器拒绝访问(403错误)

原文地址:http://www.cnblogs.com/micenote/p/7236990.html


下一篇       上一篇