When working with a new ASP.Net Core project and you choose the “API” project template you get given a ValuesController as an example for a starting point. Nearly every time you start a new project you will not require a ValuesController however when you start to debug your application it will continue to default to /api/values.

Once you delete the ValuesController instead of getting the test strings array returned in the browser, you get a “404 Page not found”.

How do we resolve this?

Navigating to launchSettings.json under the project Properties you will discover a number of profiles which drive how the project will run in Visual Studio. By default it has an IIS Express profile, and a profile named after the project which runs Kestral on the command line.

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false, 
    "anonymousAuthentication": true, 
    "iisExpress": {
      "applicationUrl": "http://localhost:59408",
      "sslPort": 44311
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication9": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

You can see from the above that there are some common properties for each profile, but the interesting one for this issue is the launch url property.

“launchUrl”: “api/values”,

This can be updated to point to the root of your application, or another default controller action route.

“launchUrl”: “”,

This allows for such tools as Swagger UI, once configured, to be the default page returned from the project.

Conclusion

We’ve looked briefly at the launchSettings.json file which is part of an ASP.Net Core project and updated the default profiles to not use the example api controller routes.

Any questions/comments then please contact me on Twitter @WestDiscGolf