Asp.Net Core change url in launchSettings.json not working

I want to change the default url ( http: // localhost: 5000 ) when I launch the website as a console application.

I edited launchSettings.json, but it doesn’t work ... it still uses port 5000:

    {
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:4230/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "website": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:80",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
+4
source share
3 answers

This is a known issue (I cannot point to a problem on GitHub since it was registered in a private repo).

+1
source

Using Kestrel, you can specify the port using the hosting.json file.

Add .json hosting with the following content to the project:

{
    "server.urls": "http://0.0.0.0:5002" 
}

publishOptions project.json

"publishOptions": {
"include": [
  "hosting.json"
  ]
}

".UseConfiguration(config)" WebHostBuilder:

        public static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build();

            var host = new WebHostBuilder()
                .UseConfiguration(config)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }
+2

You need to add the URL when creating "BuildWebHost". Hope this helps you https://github.com/aspnet/KestrelHttpServer/issues/639

Below is the code I'm using in a .net core 2.0 console application

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5050/")
            .Build();


}

Screenshot with console output

0
source

All Articles