Reputation: 5968
I have an Asp core dotnet app. The app is working properly and I'm trying to publish it to Ubuntu.
I have .Net installed on Ubuntu.
Here is the configuration file for my app (LaunchSettings.json file) :
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49855",
"sslPort": 44315
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:6001;http://localhost:6000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Basically I want my app to run on ports 6000/6001
I successfully copied the app to the server, but when I run dotnet MyApp.dll, I'm getting the error:
Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
I checked which process is running on port 5000 (through the commands fuser 5000/tcp
then ps -p PID -o comm=
). I'm getting dotnet as the process using the port 5000. I killed it and run again the command dotnet MyApp.dll
but I'm getting the same error.
Is there any way to solve that please? i.e. either making the app run from another port or make dotnet use another port?
Upvotes: 0
Views: 646
Reputation: 166
in asp.net core you can use 3 way
first way, use --urls=[url]
option for dotnet run ,
for example :
dotnet run --urls="http://localhost:6000/;https://localhost:6001/"
OR
dotnet MyApp.dll --urls="http://localhost:6000/;https://localhost:6001/"
second way, add Urls
in appsettings.json
or appsettings.Development.json
for example:
{
"Urls": "http://localhost:6000;https://localhost:6001"
}
third way, using UseUrls()
in Program class
and add configure to ConfigureWebHostDefaults
for example:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseUrls("http://localhost:6000;https://localhost:6001");
});
}
Upvotes: 3