Asp.net-Mvc

MVC 捆綁:錯誤 403

  • November 30, 2014

使用 VS'12, Asp.net - C# - InternetApplication Template, KendoUI, EF Code First

這是我的 MVCBundleConfig.cs

       bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                   "~/Scripts/jquery-{version}.js"));

       bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));

       // The Kendo CSS bundle
       bundles.Add(new StyleBundle("~/Content/kendo").Include(
               "~/Content/kendo/kendo.common.*",
               "~/Content/kendo/kendo.default.*"));

       // The Kendo JavaScript bundle// or kendo.all.min.js if you want to use Kendo UI Web and Kendo UI DataViz
       bundles.Add(new ScriptBundle("~/bundles/kendo").Include(
                                   "~/Scripts/kendo/kendo.web.min.js",
                                   "~/Scripts/kendo/kendo.aspnetmvc.min.js"));

你也應該知道我在結尾處執行了這兩行BundleConfig.cs

       bundles.IgnoreList.Clear();
       bundles.DirectoryFilter.Clear();

當我嘗試託管項目時,我收到了403 Access Denied , File Forbidden 錯誤。

我嘗試使用This Awesome Post作為參考,我確實在其中更改了一些內容,但仍然出現錯誤。

我想這是因為 KendoUI 附帶了 .min 文件,但我不能確定。

供您參考,這是我的_Layout.cshtml,以及我如何呼叫腳本。

   @Scripts.Render("~/bundles/jquery")
   @Styles.Render("~/Content/css")
   @Styles.Render("~/Content/kendo")
   @Scripts.Render("~/bundles/kendo")

嘗試改變

bundles.Add(new StyleBundle("~/Content/kendo").Include(
           "~/Content/kendo/kendo.common.*",
           "~/Content/kendo/kendo.default.*"));

bundles.Add(new StyleBundle("~/bundles/css/kendo").Include(
           "~/Content/kendo/kendo.common.*.css",
           "~/Content/kendo/kendo.default.*.css"));

然後

@Styles.Render("~/Content/kendo")

@Styles.Render("~/bundles/css/kendo")

這是因為您對 stylebundle 使用與現有目錄相同的“別名”(/Content/kendo)。

一旦您使用另一個別名(/Content/css/kendo/ 或 /Content/whatevernonexistingdir),您的問題就解決了。

但請注意:css 的“根”已更改,因此在您的 css 中使用指向子文件夾的(背景)圖像時,請考慮到這一點!

引用自:https://stackoverflow.com/questions/18474669