无法加载资源:.js优化禁止使用403

问题描述:

我正试图缩小我的.js和.css文件.

I'm trying to minify my .js and .css files.

我已经安装了包装好的Install-Package Microsoft.AspNet.Web.Optimization

I've installed the packed Install-Package Microsoft.AspNet.Web.Optimization

每当我使用BundleTable.EnableOptimizations = true;

我在客户端上收到此错误:

无法加载资源:服务器的响应状态为403(禁止)http://localhost:22773/Content/themes/elevation/v=gnDLBbf1VVRuQDXtIYn1q0P3ICZG7oiwwgxPRbaLvqI1

Failed to load resource: the server responded with a status of 403 (Forbidden) http://localhost:22773/Content/themes/elevation/v=gnDLBbf1VVRuQDXtIYn1q0P3ICZG7oiwwgxPRbaLvqI1

有人知道我在做什么错吗?

Anyone have an idea of what I'm doing wrong?

-BundleConfig信息--------------------------------

---BundleConfig info-------------------------------

 public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        BundleTable.EnableOptimizations = true;

        bundles.Add(new ScriptBundle("~/bundles/myJquery").Include(

           "~/Scripts/jquery-1.9.1.js",
          "~/Scripts/jquery-ui-1.10.1.custom.js",
            "~/Scripts/jquery.signalR-1.0.1.js",
            "~/Scripts/signalr-hubs.js",
            "~/Scripts/Controls/Select/Simple/jquery.ui.selectmenu.js"
        ));


        bundles.Add(new ScriptBundle("~/bundles/shared").Include(
            "~/Scripts/global/prototypes.js",
            "~/Scripts/global/mathutil.js",
            "~/Scripts/global/elevationevents.js"
            ));


        bundles.Add(new ScriptBundle("~/bundles/core").Include(
            "~/Scripts/elevation/core/sys.config.js",
            "~/Scripts/elevation/core/bays.js",
            "~/Scripts/elevation/core/door.js",
            "~/Scripts/elevation/core/horiziontal.js",
            "~/Scripts/elevation/core/vertical.js"));


        bundles.Add(new StyleBundle("~/Content/themes/elevation").Include(
            "~/Content/themes/dialogs/dialogs.css",
            "~/Content/themes/social/ac/acSocial.css",
            "~/Content/themes/elevation/elevation.css"
      ));
    }
}

-----------------------------我仍然没有弄清楚这个---------- -----------

-----------------------------I still have not got this figured out---------------------

我正在Windows7操作系统上使用2013 .net和iis8

I'm using 2013 .net and iis8 on a windows7 OS

这是我的最新错误,我无法将我的解决方案退出调试模式,因为如果这样做,我将在下面看到该错误.

Here is my latest error, I cannot take my solution out of debug mode, because if I do I get that error below.

    HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.

Most likely causes:
A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

Things you can try:
If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
Enable directory browsing.
Go to the IIS Express install directory.
Run appcmd set config /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the server level.
Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the site level.
Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

Detailed Error Information:
Module     DirectoryListingModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x00000000
Requested URL      http://localhost:1499/Content/themes/elevation/?v=aukmuLTC3g_fDko3eWmzqq7A8miRqgsJKXA2GO3w-pg1
Physical Path      c:\users\administrator\documents\visual studio 2013\Projects\AlumCloud\AlumCloud\Content\themes\elevation\
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\Administrator\Documents\IISExpress\TraceLogFiles\ALUMCLOUD(3)

More Information:
This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.
View more information »


这是iis8在未处于调试模式时会产生错误的url

http://localhost:1499/Content/themes/elevation/?v=aukmuLTC3g_fDko3eWmzqq7A8miRqgsJKXA2GO3w-pg1

以下是返回实际.css文件的网址,没有任何错误

http://localhost:1499/Content/themes/elevation/elevation.css

只是遇到了同样的问题.就我而言,解决方案是为Content bundle提供一个不同的名称.我认为发生这种情况是因为IIS拦截了请求并将捆绑包名称视为目录,并且因为Content文件夹确实存在,所以它返回了禁止的错误.因此,您可以将~/Content/themes/elevation重命名为~/css/themes/elevation

Just had the same issue. In my case, the solution was to give the Content bundle a different name. I think that happen because IIS intercepts the requests and treat the bundle name as a directory and since the Content folder really exists, it returns the forbidden error. So, you could rename ~/Content/themes/elevation to say ~/css/themes/elevation

bundles.Add(new StyleBundle("~/css/themes/elevation").Include(
            "~/Content/themes/dialogs/dialogs.css",
            "~/Content/themes/social/ac/acSocial.css",
            "~/Content/themes/elevation/elevation.css"
      ));

此外,请不要忘记调整您的标记/母版页以使用修改后的捆绑包名称,即

Also, don't forget to adjust your markup/master page to use the revised bundle name, i.e.

<%: Styles.Render("~/css/themes/elevation") %>

然后将位置指令添加到web.config中以允许访问包:

Then add location directives to the web.config to allow access to the bundles:

<location path="css">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="bundles">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

希望这会有所帮助.