How to set start page in dotnet core web api?

Step 1

app.UseDefaultFiles();
app.UseStaticFiles();

Step 2

Create a folder called "wwwroot". put a file called index.html

Step 3 (optional)

If you are the using the auto generated template, you can remove make the launchUrl blank like this

"launchUrl": "",

Otherwise, you will have to manually keep going to the landing page every time during localhost running.

This is the correct way. But always use UseDefaultFiles() before UseStaticFiles Otherwise it won't work.

For reference: Core fundamentals of Static Files


In Properties/launchSettings.json you can define the launchUrl

"profiles": {
    "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "launchUrl": "<your relative URL here>",
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    }
}