2016-05-10 102 views
1

從Azure中的Visual Studio 2015發佈我的應用程序時,出現此問題;它看起來是這樣的:從Visual Studio 2015在Azure中發佈應用程序不會加載.CSS

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> 

當我加入調試=「真」,在編譯一切正常:

enter image description here

我想離開這裏這幫助別人有同樣的問題,並順便我的問題:

1-爲什麼禁用調試會影響.css文件(以及其他文件)的加載方式?

2-有沒有另一種方法來糾正這一點,而不允許在我的遠程服務器上調試?

3-也許還有另一種解決方法,我錯過了我的幫助搜索,如果有人以前遇到過這個問題,請分享您的知識。

人們可以預料,這將是很常見的,畢竟我只是發表在蔚藍的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")); 
     } 
    } 
} 
+0

你可以分享你的應用程序的實際URL?看來捆綁正在搞亂你的CSS路徑。通常出現這種情況有圖標(http://stackoverflow.com/questions/19664287/bootstrap-icons-are-loaded-locally-but-not-when-online),但它可能是值得考慮的一個頁面加載的實際響應在您的實際網站上。 –

+0

當然,你可以通過訪問http://distribuidorasaturno.azurewebsites.net/ 正如我所說的,它現在的工作,但只有在遠程服務器上啓用調試完畢後,我不知道爲什麼! – Loaderon

+0

您可以在禁用調試的情況下部署代碼嗎? –

回答

2

我想我知道發生了什麼事。因此,我訪問了您的網站並在Chrome開發人員工具和您的CSS包中監控了請求/響應,我注意到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,它建議更改捆綁軟件的名稱,因爲它與服務器上的物理路徑衝突。

你可以通過改變你的包名試試?嘗試是這樣的:

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

,然後在您的視圖頁面更改從/Content/CSS/CSSBundle的路徑。

這應該可以解決這個問題。

+0

它的工作!非常感謝你!這是一個可憐的微軟自己的Bundle模板無法正常工作,但無論如何xD – Loaderon

1

我想你應該去找你的BundleConfig.cs類。它可能在最近的變化發佈後被破壞。將您的BundleConfig.cs文件發佈到您添加stylebundles的位置。

+0

其實我覺得我從來沒有修改它:O型 這是ASP.NET MVC5模板,我將修改我的答案張貼。 – Loaderon

相關問題