I'm trying to use .NET 5.0 on Linux, using VS Code.
I've created an empty directory, ran "code ." in it to open it up in VS Code, then created the sample project with:
dotnet new webapi -n Experimenting
When the "Required assets to build and debug are missing from 'experiments'. Add them?" dialog appeared, I clicked "Yes".
I ran the build task, then selected "Start Debugging" from the "Run" menu.
The project appears to run, and it opened up a Chrome browser tab to https://localhost:5001/, and the tab displays HTTP ERROR 404.
The "Expementing" profile in lauchSettings.json has applicationUrl set to "https://localhost:5001;http://localhost:5000", and the debug console includes:
Now listening on: https://localhost:5001 Now listening on: http://localhost:5000
So the ports seem to be correct.
If I try to open a browser tab on http://localhost:5000, it redirects to https://localhost:5001, and then shows the 404.
What am I missing?
The comment by jmoerdyk is correct - if I try https://localhost:5001/swagger, I get the swagger page.
In .NET Framework, Web API creates a landing page at the domain root. .NET Core does not.
The question, then, is why is the browser tab opening up at https://localhost:5001, and not at https://localhost:5001/swagger?
I had noticed this in launchSettings.json:
"profiles": {
"IIS Express": {
...
},
"Experimenting": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
And I thought that should open up the browser pointing to the swagger page. Browsing around I've seen statements that that launchSettings.json is not used by VS Code, but it clearly is, because if I change ports in applicationUrl, I the swagger page running on the new ports.
But launchUrl seems to be ignored.
Browsing around the web gives me the same sort of wrong and outdated answers that is typical for .NET Core questions, but I eventually tried setting the uriFormat in launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
...
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"uriFormat": "%s/swagger"
},
...
},
]
}
The link in the comment explains how this is supposed to work - kinda.