2017-07-26 87 views
0

我正在構建一個Angular 2應用程序,並使用.NET Core和Webpack將我的靜態資源編譯到dist文件夾中。我正在使用一個插件來構建我的index.html文件,並將其放入我的wwwroot/dist文件夾中,但在如何配置我的Startup.cs文件以查找dist文件夾中的默認文件方面苦苦掙扎。.NET核心改變我的默認index.html文件的位置

目前,我有...

 app.UseDefaultFiles(); 
     app.UseStaticFiles(); 

在我startup.cs文件,但它不會使用在我的DIST文件夾中生成中的index.html。關於我需要改變的任何想法?該文檔沒有給出我能找到如何做到這一點的很多參考。

謝謝。

+0

不什麼都存在於wwwroot或dist文件夾中? –

+0

@TravisBoatman我也有一個圖像和圖標文件夾。 – dev53

回答

3

您可以使用如下代碼的下方,但是當你把空的index.html它只能wwwroot文件文件夾的根:

 app.UseDefaultFiles(); 
     // Serve wwwroot/dist as a root 
     app.UseStaticFiles(new StaticFileOptions() 
     { 
      FileProvider = new PhysicalFileProvider(
       Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\dist")) 
     }); 

RequestPath默認是空的,所以根路徑將顯示您的wwwroot \文件夾DIST index.html或default.html中。

UPDATE:有簡單而漂亮的解決方案使用來處理這個問題的WebRootProgram.cs象下面這樣:

public static void Main(string[] args) 
{ 
    var host = new WebHostBuilder() 
     .UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "dist")) 
     .UseKestrel() 
     .UseContentRoot(Directory.GetCurrentDirectory()) 
     .UseIISIntegration() 
     .UseStartup<Startup>() 
     .UseApplicationInsights() 
     .Build(); 

    host.Run(); 
} 

ConfigureStartup.cs方法,你只需要使用:

app.UseDefaultFiles(); 
    app.UseStaticFiles();