1

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?

2
  • I notice that simply redirects to index.html. I am pretty much at the same point you are and I'm wondering how to get it to load index.html as a default route. Commented Jun 13, 2016 at 5:01
  • In my case app.UseDefaultFiles(); is showing error? any solution?? Commented Nov 24, 2016 at 11:04

1 Answer 1

10

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).

Sign up to request clarification or add additional context in comments.

3 Comments

Still not routing my HTML page i am using ASP.NET Web API MVC Core project? Any Suggestion?
Better yet, do not enter anything for launchUrl, leave it as empty string like: "launchUrl": "" This way, the server will launch the site at localhost via the port configured in the project > properties > Debug > Web Server Settings and as long as you include app.UseDefaultFiles() and UseMvc() your default page will be served up.
have same issue, html page is blank after these settings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.