问题
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.
When I start the app by default it comes up with localhost:4578/api/values
from the default API controller as startpage.
However, I want it to show index.html
by default which is located in wwwroot
and is hosting my Angular2
app.
In Startup.cs
the Configure
method looks like this:
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
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.
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.
How can I change this?
回答1:
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:
and change the launchUrl value to: http://localhost:4578 (from http://localhost:4578/api/values).
来源:https://stackoverflow.com/questions/37770131/net-core-rc2-webapi-with-index-html-as-default-page