2017-04-08 43 views
0

好吧,所以我不知道我在這裏失蹤。我想要做的是顯示我的靜態css文件鏈接到我的索引頁面。我已經加載了依賴關係,並將它放在startup.cs中,希望有人能告訴我在哪裏搞亂了它。 ALl這個應該做的就是在索引中將h1轉換爲綠色。頁面的加載恰好不會改變顏色。靜態文件不通過wwwroot c加載#

Project.json 

"dependencies": { 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 


Startup.cs 

public void Configure(IApplicationBuilder app, ILoggerFactory 
loggerFactory) 
     { 
      // Use the Mvc to handle Http requests and responses 

      loggerFactory.AddConsole(); 
      app.UseStaticFiles(); 
      app.UseDeveloperExceptionPage(); 
      app.UseMvc(); 
     } 

Index.cshtml 

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset='utf-8'> 
     <title>Index</title> 
     <link rel="stylesheet" href="~/css/style.css"/> 
    </head> 
    <body> 
     <div id = "test"> 
      <h1>Hello ASP.NET Mvc!</h1> 
     </div> 
    </body> 
</html> 

Style.css 

*{ 
margin: 0px; 
padding: 0px; 
} 

h1{ 
    color: green; 
} 



    Structure of wwwroot 

    wwwroot 
     css 
     style.css 
+0

你有沒有研究通過IIS設置中啓用靜態內容? –

+0

是啊我在學校學習所有這一切,並遵循所有的東西,甚至resarched微軟我似乎有它設置正確的思想我得到了一些愚蠢的破 –

+0

你可以瀏覽到/css/style.css? –

回答

0

閱讀本使靜態內容: link

+0

我檢查了它,但是已經清理了,並重新安裝了它,但沒有運氣ty –

+0

你確定css在你的項目和那條路上?當你查看內容時你能在IIS中看到它嗎?您也可以嘗試使用相對路徑(「href =」../ css/style.css「) –