我已經建立了一個空的WebAPI項目,其中.NET Core rc2
已與Angular2 rc1
連線。 Angular會處理所有相關的視圖,並且WebAPI是後端。使用index.html作爲默認頁面的.NET Core rc2 WebAPI
當我在默認情況下啓動應用程序時,它會從默認的API控制器提供localhost:4578/api/values
作爲首頁。
但是,我希望它顯示index.html
默認位於wwwroot
和託管我的Angular2
應用程序。
在Startup.cs
的Configure
方法是這樣的:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
app.Run(ctx =>
{
ctx.Response.Redirect("/index.html");
return Task.FromResult(0);
});
}
app.UseStaticFiles
和app.Run
拉姆達需要在地方手動重定向到index.html
工作,但它仍與/api/values
出來作爲默認啓動頁面。
我知道,爲了調試目的,我可以很容易地更改起始頁面,但我想更改它,以便在我託管它時始終將index.html
作爲起始頁面。
我該如何改變這種情況?
我注意到,只是重定向到index.html。我幾乎和你同樣的觀點,我想知道如何讓它加載index.html作爲默認路由。 – Samir
在我的情況app.UseDefaultFiles();顯示錯誤?任何解決方案 –