Ehsan Ghanbari

Experience, DotNet, Solutions

Specifying the bounded port in asp.net core

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

 

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to use PagedList In asp.net MVC
How to query over Icollection<> of a type with linq
Domain driven design VS model driven architecture
What's the DDD-lite?
Redis as a cache server
comments powered by Disqus