web-dev-qa-db-ja.com

リソースの読み込みに失敗しました:403は.js最適化で禁止されています

.jsファイルと.cssファイルを縮小しようとしています。

パックされたInstall-Package Microsoft.AspNet.Web.Optimizationをインストールしました

いつでもBundleTable.EnableOptimizations = true;を使用して最適化をアクティブにします

クライアントでこのエラーを受け取ります:

リソースの読み込みに失敗しました:サーバーは403(禁止)のステータスで応答しましたhttp://localhost:22773/Content/themes/elevation/v=gnDLBbf1VVRuQDXtIYn1q0P3ICZG7oiwwgxPRbaLvqI1

誰かが私が間違っていることを知っていますか?

--- BundleConfig情報-------------------------------

 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"
      ));
    }
}

-----------------------------私はまだこれを理解していません------------- --------

Windows 7 OSで2013 .netとiis8を使用しています

これが私の最新のエラーです。解決策をデバッグモードから外すことはできません。その場合、以下のエラーが発生します。

    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ファイルを返すURLです

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

ちょうど同じ問題がありました。私の場合、解決策はコンテンツバンドルに別の名前を付けることでした。 IISがリクエストをインターセプトし、バンドル名をディレクトリとして処理し、コンテンツフォルダが実際に存在するため、禁止されたエラーを返します。そのため、~/Content/themes/elevation 言う ~/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"
      ));

また、改訂されたバンドル名を使用するようにマークアップ/マスターページを調整することを忘れないでください。

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

次に、ロケーションディレクティブをweb.configに追加して、バンドルへのアクセスを許可します。

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

お役に立てれば。

42
Denis Ivin

リソースの実際のパスと同様のバンドル名を維持する必要があります。それ以外の場合、debug='false'またはBundleTable.EnableOptimizations = true;でコンパイルすると、システムはリソースを見つけることができません。システムがバンドル名を使用してリソースのリンクを生成するためです。バンドル名は次のようになります-

bundles.Add(new ScriptBundle("~/Scripts/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("~/Scripts/global/shared").Include(
    "~/Scripts/global/prototypes.js",
    "~/Scripts/global/mathutil.js",
    "~/Scripts/global/elevationevents.js"
));

bundles.Add(new ScriptBundle("~/Scripts/elevation/core/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/dialogs/dialog").Include(
    "~/Content/themes/dialogs/dialogs.css"
));

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

EditこれはIIS 6.で機能しますが、IIS 7または7.5ソリューションは別のものです。IIS 7.5でアプリケーションをデプロイしたときに同じ問題に直面しました。解決策は ASP.NET MVC 4 on =で説明されているように修正プログラムをインストールすることです。 IIS 7.5、404を返します。拡張子のないルートマッピングで何かを行うこと および ASP.NET 4.5 MVC 4がWindows Server 2008で機能しないIIS = 7

3
th1rdey3

/ themes/elevation?v = gnDLBbf(を使用)ではなく、実際に/ elevation/v = gn ...である必要がありますか?

0
Agat

受け入れられた回答に記載されているように、割り当てたバンドル名が実際の既存のフォルダーと競合しています。例として、以下を検討してください。

bundles.Add(new StyleBundle("~/content/epic").Include(
    "~/Content/Epic/StickyFooter.css"));

OPによって指摘されたのと同じタイプのエラーが表示されます。

{myURL}/content/epic/?v=YTZL7Up6r-0uQblkv6unjKN5Nfb3uwtE0bPz9nxbjDc1 Failed to load 

これは、オプティマイザーが作成しようとしている仮想パス(コンテンツ/エピック)がサイトの既存のフォルダーパスになっているためです(ルートに「コンテンツ」というフォルダーがあり、「エピック」というフォルダーが含まれています)。 。バンドルパスを次のように変更すると、

bundles.Add(new StyleBundle("~/content/epic2").Include(
    "~/Content/Epic/StickyFooter.css"));

「content」フォルダ内に「epic2」というフォルダがないため、この問題は発生しなくなりました。

受け入れられた回答とは逆に、「〜/ Content/a/b /」などのバンドルディレクトリを「〜/ css/a/b」に変更しないことをお勧めします。スタイルシートに相対参照が含まれていると、別の潜在的な問題が発生するためです。外部ファイルに。

このスニペットを含む私のAjaxLoadAnimation.cssスタイルシートを検討してください:

...
background: rgba( 255, 255, 255, .5 ) url('images/spin.gif') 50% 50% no-repeat;
...

参照が最適化および非最適化コンパイルで機能することを確認するには、バンドルのパスがバンドル内の各アイテムのパスと一致していることを確認してください。スタイルシートが〜/ Content/my/pathにある場合、バンドルも〜/ Content/my/pathで始まる必要があります。 OPの問題を回避するには、名前(私の場合は "sharedcss")が既存のフォルダーと競合しないことを確認してください。

bundles.Add(new StyleBundle("~/Content/my/path/sharedcss").Include(
    "~/Content/my/path/bootstrap.css",
    "~/Content/my/path/font-awesome.css",
    "~/Content/my/path/AjaxLoadAnimation.css"));

うまくいけば、これは他の人々を同じフラストレーションから救うでしょう。

0
Timothy Kanski