Glenn Jansson
Glenn Jansson

Reputation: 85

ASP.NET Core Launch Profiles with Multiple Sites and Environment Variables

So I'm new to ASP.NET Core and I'm trying to configure environment variables in Visual Studio for the site we're developing. Right now I've got a Development launch profile, which I want to use with our remote test site (rather than localhost). We have multiple projects in the solution, and I want to launch two of them - the main site (test.###.com) as well as the API test site with Swagger (api.test.###.com). Only I'm a little unsure which launch profile to choose, and I'm running into problems with either choice.

Launch Profile Options

If I choose Development for both the test site and the API test subdomain, both sites will launch, but I get the following exception in the API site's Program.cs: System.IO.IOException: 'Failed to bind to address https://[::]:443: address already in use.'

IOException

I've also tried using IIS Express, but it'll launch the API site in localhost. I tried switching the iissettings in launchSettings.json to point to the api.test site rather than localhost, but I just run into an "Unable to connect to web server 'IIS Express'. Failed to register URL for site. Access is denied." error message.

Where am I going wrong? What's the right way to set this up?

Upvotes: 0

Views: 48

Answers (1)

Rosco
Rosco

Reputation: 2514

To fix the port conflict, just change the port that your app is using. See the launch settings docs. A simple fix is to edit Properties\launchSettings.json and change the https link port to 44310.

You should only have one launch profile and have different settings (like api host name) in appsettings.Development.json. Then your code should use this setting to connect to the correct host for the environment.

I recommend reading configuration in .net core to understand how to setup different environments and their configuration.

e.g. for Development appsettings.Development.json might look like this:

{
  "ApiSettings": {
    "Host": "localhost:44320"
  }
}

and set the Api project to use the matching port.

for Production appsettings.json might look like this:

{
  "ApiSettings": {
    "Host": "api.ourwebsite.com"
  }
}

Upvotes: 0

Related Questions