Blog

Filter posts by Category Or Tag of the Blog section!

Specifying the bounded port in asp.net core

Tuesday, 08 January 2019

I just faced a problem in asp.net core which was specifying the bounded port. There is an extension in WebHostBuilder named  UseUrls() to specify that:

 

 public class Program

    {

        public static void Main(string[] args)

        {

            CreateWebHostBuilder(args)

                .UseKestrel()

                .UseContentRoot(Directory.GetCurrentDirectory())

                .UseIISIntegration()

                .UseStartup<Startup>()

                .UseUrls("http://localhost:5002/")

                .Build()

                .Run();

        }

 

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>

            WebHost.CreateDefaultBuilder(args)

                .UseStartup<Startup>();

    }

 

Rather than the solution above, you can specify it in launchSettings.json under properties of asp.net core. Look at the default values of the file:

 

{

  "$schema": "http://json.schemastore.org/launchsettings.json",

  "iisSettings": {

    "windowsAuthentication": false,

    "anonymousAuthentication": true,

    "iisExpress": {

      "applicationUrl": "http://localhost:60901",

      "sslPort": 44343

    }

  },

  "profiles": {

    "IIS Express": {

      "commandName": "IISExpress",

      "launchBrowser": true,

      "launchUrl": "api/values",

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

    },

    "Khorjin.Core.API": {

      "commandName": "Project",

      "launchBrowser": true,

      "launchUrl": "api/values",

      "applicationUrl": "https://localhost:5001;http://localhost:5000",

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

    }

  }

}

 

In applicationUrl  you can even initial more than one Url separated by a semicolon:

 

"applicationUrl": "http://localhost:60901;http://localhost:5002",

 

Category: Software

Tags: Asp.Net

comments powered by Disqus