【发布时间】:2016-09-05 13:51:07
【问题描述】:
我在 Azure 中从 Visual Studio 2015 发布我的应用程序时遇到了这个问题;它看起来像这样:
显然它没有正确加载 .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" 时,它工作正常:
我想把这个留在这里帮助其他有同样问题的人,顺便问一下我的问题:
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"));
}
}
}
【问题讨论】:
-
你能分享你的应用程序的实际 URL 吗?捆绑似乎弄乱了您的 CSS 路径。通常情况下,图标 (stackoverflow.com/questions/19664287/…) 会发生这种情况,但可能值得查看对实际网站上页面加载的实际响应。
-
当然可以通过distribuidorasaturno.azurewebsites.net访问,我说过,现在可以了,但是只有在远程服务器启用调试后,我不知道为什么!
-
你可以在禁用调试的情况下部署你的代码吗?
-
是的,我可以在禁用调试的情况下发布我的页面,但它在不加载 css 的情况下显示,如第一张图片所示。请记住,这发生在远程和本地 PC 上,您知道为什么调试会影响 css 的加载方式吗?
-
基本上,当您打开调试时,CSS 和 JS 捆绑就到位了。我的怀疑是你的捆绑发生了一些奇怪的事情,阻止了 CSS 正确加载。这就是为什么我希望您在不打开调试的情况下发布。
标签: c# css visual-studio azure visual-studio-2015