hholtij
hholtij

Reputation: 2936

.NET Core rc2 WebAPI with index.html as default page

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?

Upvotes: 1

Views: 4083

Answers (1)

JC1001
JC1001

Reputation: 516

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:

enter image description here

and change the launchUrl value to: http://localhost:4578 (from http://localhost:4578/api/values).

Upvotes: 10

Related Questions