【问题标题】:Bundling - Application Path error捆绑 - 应用程序路径错误
【发布时间】:2014-02-21 08:50:28
【问题描述】:

我使用 Microsoft.AspNet.Web.Optimization nuget 包进行 css 和 js 捆绑和缩小。

我在这个路径~/bundles/shared.css创建一个包

BundleTable.Bundles.Add(
    new StyleBundle("~/bundles/shared.css")
       .Include(
        "~/Style/DevexpressAdapter.css",
        "~/Style/Site.css",
        "~/js/jquery-ui-1.10.4.custom/css/flick/jquery-ui-1.10.4.custom.min.css"));

当我在 localhost 上运行项目时(使用 Visual Studio 中的 CTRL+F5),它运行良好。如果我点击http://localhost/bundles/shared.css,那么我会为我添加到包中的所有文件获得缩小和组合的 css。

但是在发布的位置,就不行了。

该网站在http://192.168.1.8/MyApp/ 地址运行。

当我查看 html 时,压缩包的 url 是 src="/MyApp/bundles/shared.css"。但是,如果我点击http://192.168.1.8/MyApp/bundles/shared.css,我会收到资源未找到错误。如果我也点击http://192.168.1.8/MyApp/MyApp/bundles/shared.css 我会得到同样的错误。

发生了什么,我该如何解决这个问题?我无法在生产服务器上触摸任何东西。我只能将文件复制到我有权访问的共享文件夹中。

似乎捆绑包的 url 没有正确解析。 我希望渲染包的 url 不会包含 /MyApp/ 部分

【问题讨论】:

    标签: c# javascript asp.net css bundling-and-minification


    【解决方案1】:

    不提供虚拟路径,尝试使用物理路径,方法如下

    Server.MapPath().

    【讨论】:

    • 一个Bundle的路径必须始终是应用程序的相对url而不是物理路径,否则会抛出异常。此外,bundle 不是驻留在磁盘某处的实际文件。它是在浏览器访问捆绑包的 url 时动态创建并返回到响应的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 2016-07-09
    • 2013-10-13
    • 2018-02-21
    相关资源
    最近更新 更多