Asp.net-Web-Api
如何在 dotnet core web api 中設置起始頁?
我嘗試使用 dotnet core web api 建構一個 web 應用程序,但我不知道如何將 index.html 設置為起始頁,這可以使用 dotnet framework web api 輕鬆完成。我試圖用它
app.UseDefaultFiles();app.UseStaticFiles();來解決這個問題,但是,它沒有用。
如果您使用靜態文件作為預設頁面,以下程式碼可以幫助您。
app.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new List<string> { "index.html" } });如果您使用的是 MVC 視圖,只需添加路由角色。
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}"); });
在
Properties/launchSettings.json您可以定義launchUrl"profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "<your relative URL here>", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } }