c# - 从 Visual Studio 2015 在 Azure 中发布应用程序不会加载 .CSS

标签 c# css visual-studio azure visual-studio-2015

我在 Azure 中从 Visual Studio 2015 发布应用程序时遇到了此问题;它看起来像这样:

enter image description here

显然它没有正确加载 .css 文件(谁知道还有什么)。

我做了很多调查,但与我的预期相反,很难找到问题的根源,但在一些丢失的论坛中,我发现 web.config 在发布时其属性发生了变化,我的本地web.config 看起来像这样:

<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>

我的远程 web.config 像这样:

<system.web>
<authentication mode="None" />
<compilation targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>

当我在编译中添加 debug="true"时,它工作正常:

enter image description here

我想将其留在这里,以帮助其他遇到同样问题的人,顺便说一下我的问题:

1- 为什么禁用调试会影响 .css 文件(可能还包括其他文件)的加载方式?

2-是否有另一种方法可以在不允许在远程服务器上进行调试的情况下纠正此问题?

3-也许我在寻求帮助时错过了另一种解决方法,如果有人以前经历过这种情况,请分享您的知识。

人们可以预料到这种情况会很常见,毕竟我只是在 azure xD 中发布一个应用程序
值得一提的是,我的应用程序还可以使用数据库,我现在将尝试学习如何在 azure xD 上实现它

谢谢!

编辑: BundleConfig.cs

using System.Web;
using System.Web.Optimization;

namespace Distribuidora_Saturno
{
    public class BundleConfig
    {
        // Para obtener más información sobre Bundles, visite http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Utilice la versión de desarrollo de Modernizr para desarrollar y obtener información. De este modo, estará
            // preparado para la producción y podrá utilizar la herramienta de compilación disponible en http://modernizr.com para seleccionar solo las pruebas que necesite.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/CSS").Include(
                      "~/Content/CSS/bootstrap.css",
                      "~/Content/CSS/site.css"));
        }
    }
}

最佳答案

我想我知道发生了什么。因此,我访问了您的网站并在 Chrome 开发人员工具中监控了请求/响应,对于您的 CSS bundle ,我注意到 IIS 正在响应 403 错误。

enter image description here

出于好奇,我访问了捆绑链接,这就是我得到的:

enter image description here

所以我在捆绑文件上搜索了 403 错误并遇到了这个线程:ASP.NET MVC framework 4.5 CSS bundles does not work on the hosting它建议更改 bundle 的名称,因为它与服务器上的物理路径冲突。

您可以尝试更改 bundle 名称吗?尝试这样的事情:

        bundles.Add(new StyleBundle("~/CSSBundle").Include(
                  "~/Content/CSS/bootstrap.css",
                  "~/Content/CSS/site.css"));

然后将 View 页面中的路径从 /Content/CSS 更改为 /CSSBundle

这应该可以解决问题。

关于c# - 从 Visual Studio 2015 在 Azure 中发布应用程序不会加载 .CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37140992/

相关文章:

C#:嵌套条件与 continue 语句

c++ - 有没有办法比较 Visual Studio 中的 obj 文件?

c++ - 我可以在 OS X 上使用 windows.h 吗?

visual-studio - 在 Windows 上对嵌入式软件进行原型(prototype)设计和模拟

c# - 如何旋转游戏对象?

c# - 将数组从 C# (Mono) 编码到 C++

c# - WPF - 使用嵌套的 HierarchicalDataTemplate 在 TreeView 中刷新 CollectionView 而不会丢失选择

css - 当元素大于图像时如何使用图像 Sprite ?

css - 如何使用 create react app 在特定的 React 组件中显示图像?

html - CSS |无法将图像放入主要内容