带有index.html作为默认页面的.NET Core rc2 WebAPI [英] .NET Core rc2 WebAPI with index.html as default page
问题描述
我已经使用 .NET Core rc2
设置了一个空的WebAPI项目,并使用 Angular2 rc1
进行了连接.Angular将处理所有与视图相关的内容,而WebAPI是后端.
I have set up an empty WebAPI project with .NET Core rc2
and have it wired up with Angular2 rc1
. Angular will handle everything view related and the WebAPI is the backend.
默认情况下,当我启动该应用程序时,它会从默认API控制器中以 localhost:4578/api/values
开头.
When I start the app by default it comes up with localhost:4578/api/values
from the default API controller as startpage.
但是,我希望它默认显示 index.html
,它位于 wwwroot
中,并托管我的 Angular2
应用.
However, I want it to show index.html
by default which is located in wwwroot
and is hosting my Angular2
app.
在 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
lambda才能手动重定向到 index.html
仍然带有/api/values
作为默认开始页面.
app.UseStaticFiles
and the app.Run
lambda need to be in place for the manual redirect to index.html
to work but it still comes up with /api/values
as default start page.
我知道出于调试目的,我可以轻松更改起始页,但我想对其进行更改,以便在托管时始终将 index.html
用作起始页.
I know that for debugging purposes I can change the start page easily but I want to change it such that when I host it it always serves index.html
as start page.
我该如何更改?
推荐答案
在创建新的空WebAPI项目时,默认情况下launchsettings.json文件指向api/values.要对其进行更改,请转到您项目中的launchsettings.json文件:
When creating a new empty WebAPI project, the launchsettings.json file points to api/values by default. To change it, go to the launchsettings.json file in your project:
,然后将launchUrl值更改为: http://localhost:4578 (来自
and change the launchUrl value to: http://localhost:4578 (from http://localhost:4578/api/values).
这篇关于带有index.html作为默认页面的.NET Core rc2 WebAPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!