Setting a Port in both project.json and launchSettings.json - asp.net

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.

Related

Problem with project running on wrong localhost

I have a Web API project (MapBackend). I want to start the project at MapBackend-applicationUrl (https://localhost:5001) bu it starts ssl port (https://localhost:44365/). So this project is not working. How can I solve this problem ?
Proof that it doesn't work:
Proof 1
Proof 2
This is my launchSettings.json file:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:43928",
"sslPort": 44365
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MapBackEnd": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Select the Kestrel configuration from Visual Studio dropdown box:
In your case the name under the "IIS Express" will be "MapBackEnd"
Check your appsettings.json file and see if you have something like this inside:
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://*:5000"
}
}
}
On this port your application will run when started from the VisualStudio.

.NET Core project not reading launchSettings.json

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.

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"
}
}
}

.NET Core, change databse settings

Sorry, I've searching but can't found an answer to this. First time using .NET, I need to change the settings for the database. Currently is using IIS express, now I have to use a remote sql server. The launchSettings.json settings is this.
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:42793",
"sslPort": 44355
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"factoringxs_autox": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5011;http://localhost:5010"
}
}
}
So, I have the credentials (IP db, db name, user and password) for the sql server. How can I configure it in launchSettings.json?

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.

Resources