【问题标题】:MVC bundeling : Err 403MVC 捆绑:错误 403
【发布时间】:2013-08-30 17:53:40
【问题描述】:

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

这是我的 MVC BundleConfig.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")

【问题讨论】:

    标签: asp.net-mvc kendo-ui web-deployment bundling-and-minification kendo-asp.net-mvc


    【解决方案1】:

    尝试改变

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

    【讨论】:

    • 太棒了,我猜他们都在 /Content 中导致了问题?? - 也感谢您的快速回复!
    • 对于那些感兴趣的人:使用~/Content 作为StyleBundle 不起作用,因为它已经是一个现有的文件夹。
    【解决方案2】:

    这是因为您为 stylebundle 使用了与现有目录相同的“别名”(/Content/kendo)。

    一旦您使用另一个别名(/Content/css/kendo/ 或 /Content/whatevernonexistingdir),您的问题就解决了。

    但请注意:css 的“根”已更改,因此在您的 css 中使用指向子文件夹的(背景)图像时,请考虑到这一点!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多