.NET Core project not reading launchSettings.json - .net-core

I have a web app using .NET Core 3.1, everything launches fine:
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Only thing is that those ports aren't the ones specified in my launchSettings.json file.
A little back story: Originally both those localhosts were specified in the launchSettings.json file, then I eliminated the 5001 one, and it only started the 5000, which is what I wanted.
All of a sudden the 5001 is back, and no matter what I change in the launchSettings.json file it reverts to both 5000 and 5001, I event deleted the launchSettings.json file and it still listens on the same address/ports, I don't know where it's reading it from.
Just for reference, this is my current launchSettings.json file, it's supposed to be reading from the StudentsWebApp profile:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61527",
"sslPort": 44325
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"StudentsWebApp": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
This is how I'm running the web app, just clicking the play button or F5 for the startup project:
Why is it bypassing my launchSettings.json file?

After more searching around I got it to work:
Adding this in Project Properties > Debug Tab > Application arguments
--urls=http://localhost:5000/
This way it reads exactly what address/port you want.

Related

Cannot browse to site hosted in IIS Express even though successfully registered

I'm trying to run an ASP.NET Core MVC application (100% template) in IIS Express. It seems the site is already hosted in IIS Express, but when I open the site in browser, I got the generic error "This site can't be reached". Any idea?
From Visual Studio:
Starting IIS Express ...
Successfully registered URL "http://localhost:55516/" for site "WebApplication1" application "/"
Successfully registered URL "https://localhost:44331/" for site "WebApplication1" application "/"
Registration completed for site "WebApplication1"
IIS Express is running.
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
Looking at DevTool, this is the response I got:
My launchSettings.json:
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": false,
"iisExpress": {
"applicationUrl": "http://localhost:55516",
"sslPort": 44331
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication1": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Edit: Interestingly, would not run if I F5 from VS. If I run "dotnet run" from CLI, it runs perfectly fine... Why???

Error after modifying launchSettings: The launch profile "(Default)" could not be applied

I'm setting up my project to use dotnet watch run in my launchSettings.json under Visual Studio 2019 Preview 16.9.0
Below is my launchSettings.json
{
"profiles": {
"MyWebsite": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
Here is the ouput when I hit CTRL+F5
watch : Started
The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.
[17:38:49 INF] Starting up
[17:38:49 INF] User profile is available. Using 'C:\Users\MyUser\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
[17:38:50 INF] Now listening on: http://localhost:5000
[17:38:50 INF] Now listening on: https://localhost:5001
[17:38:50 INF] Application started. Press Ctrl+C to shut down.
[17:38:50 INF] Hosting environment: Development
[17:38:50 INF] Content root path: C:\dev\MyWebsite\src\MyWebsite
I don't understand why I have this message :
The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.
According to this solution https://stackoverflow.com/a/65666418/1026105 this is not supposed to happen.
How can I troubleshoot this messages ?
just Change
"MyWebsite": {
"commandName": "Executable",
to
"MyWebsite": {
"commandName": "Project",
For me, changing commandName from Executable to Project made the error message go away, but also disabled the dotnet watch behaviour altogether.
I fixed the issue by adding a separate Project profile as well as the Executable one - I assume the Project profile then serves as the 'default' profile to which the error message refers.
So it's:
{
"profiles": {
"MyWebsite": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"MyWebsite-Watch": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}

IdentityServer4 Quickstart issues (self host server set up)

I am currently at this page of the IdentityServer 4
guide and I am trying to start the server.
my properties
However, when I run it, my browser pops up this page http://localhost:5000 and it is not available (not accessible as it there is no connection)
May I know how to host the server ? I follow the tutorial exactly
I did verify that if I use the JSON from the sample on Github it then hits the discovery endpoint correctly; replace the JSON created by the template, with this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5000",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SelfHost": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000"
}
}
}

How do I add production settings to my luanchSettings.json file for production?

I want to setup my dotnet core mvc application to run on ubuntu.
How do set my launch settings.json file for production environment?
I have this currently, but not sure how to change the applicationUrl for production and keep what I have for development. Very confused...
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:17009",
"sslPort": 44319
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApp.Brain": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
launchSettings.json is only meant for development purposes - to tell dotnet run or Visual Studio / IDEs what to set up.
For production, you can for example create an appsettings.Production.json containing something like
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:1234"
}
}
}
}
Or use other ways of configuring the endpoint, like the ASPNETCORE_URLS environment variable or using a command line parameter when staring up the app (dotnet yourapp.dll --urls "http://*:1234").
See Kestrel Options documentation for other configuration options for the Kestrel server (default on linux) or Host and Deploy ASP.NET Core documentation for different hosting options on linux.

Setting a Port in both project.json and launchSettings.json

I want my project to start on a particular port using both IIS Express and Kestrel in Visual Studio, using the 'IIS Express' or 'web' start button.
By default, the launchSettings.json file contains a specific port number for IIS Express. However, Kestrel is always started on the default port 5000. How can I get Kestrel to also start on the same port as IIS Express?
launchSettings.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5020/",
"sslPort": 44320
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"Hosting:Environment": "Development"
}
},
"web": {
"commandName": "web",
"environmentVariables": {
"Hosting:Environment": "Development"
}
}
}
}
project.json Extract
{
...
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
...
}
I have tried changing the web command in project.json to:
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5020"
However, this completely stops the site starting in IIS Express.

Resources