【问题标题】:The HTML references my CSS differently based upon deployment machineHTML 根据部署机器不同地引用我的 CSS
【发布时间】:2014-05-19 09:25:15
【问题描述】:

我的 MVC 4 站点使用 Bundle.Config 类添加 CSS 文件

bundles.Add(new StyleBundle("~/Content/Styles").Include(
  "~/Content/css/website.css", 
  "~/Content/css/banner.css"));

在我的本地主机上,当我查看源代码时,HTML 文件呈现为

<link href="/Content/css/website.css" rel="stylesheet"/>
<link href="/Content/css/banner.css" rel="stylesheet"/>

我现在已经实时部署了我的网站,但源代码只呈现了 1 行

<link href="/Content/Styles?v=fxCdHAOgPDvcROxkMfEwGQggO9uCfzckN3PaN8BOIzI1" rel="stylesheet"/>

奇怪的是,大多数 CSS 仍然显示(但图像不显示)。

我认为问题不在于我的 web.config 文件,因为本地和实时共享同一个文件。

我的问题是,如何消除这种行为并让实时服务器以与本地主机相同的方式呈现 HTML?

【问题讨论】:

    标签: css .net asp.net-mvc iis rendering


    【解决方案1】:

    捆绑将您的 css 压缩到一个文件中,为了使您的图像正常工作,您需要设置捆绑包,以便 ~/Content/Styles 与您的实际 css 相关,因此将其设置为类似 ~/Content/css/Styles

    如果您不希望在部署的站点上发生捆绑,请查看 this post

    【讨论】:

      【解决方案2】:

      公共类 LessTransform : IBundleTransform { 公共无效进程(BundleContext 上下文,BundleResponse 响应) { response.Content = Less.Parse(response.Content); // 这里的断点。 response.ContentType = "文本/css"; } }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多