31

I am writing an ASP.NET Core application and I have a launchSettings.json file with the following content:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50251",
      "sslPort": 44349
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "AspNetDockerDemo": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}"
    }
  }
}

Question: Where are the { } placeholders substituded and where are the values definied by which they are substituted? What will I have to do if I want to define such values on my own?

4
  • Posting some of your code can make you question more clear and it's more likely to get accurate answer. Commented Sep 21, 2018 at 13:58
  • 7
    Thank you for your response - actually the launchSettings.json file is a configuration for VisualStudio to config the execution environment. So there is no application code that will handle this data. The quetion is by what values the parameters Scheme and ServiceHost in the execution environment are set/replaced. Commented Sep 21, 2018 at 17:53
  • What is your asp.net core version and vs version? I made a test with asp.net core and docker, but, I did not see this useage. Please share us more information about this useage you know. Commented Sep 24, 2018 at 8:45
  • 1
    I am using ASP.NET Core 2.1 and Visual Studio 2017 (Version 15.8.5) Commented Sep 24, 2018 at 12:11

3 Answers 3

31

This doesn't answer your question, but if you're asking because you want consistent host port numbers while debugging like I did, you can do this by adding httpPort and sslPort to the launchSettings.json file.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

"httpPort" and "sslPort" will map the specified host port to the container's port "80" and "443", respectively.
Very useful, thanks!
25

Since you're using Visual Studio's Docker integration, you've obviously noted that it randomly selects port mappings for you.

One way to change this is to right click on your asp.net core app, select Add -> Container Orchestration Support. This will attempt to regenerate your Dockerfile and .dockerignore files, which you may decline to do if you've made substantial modifications to your existing files (note: if you have, it may cause other issues with the following instructions). It will also generate some docker-compose settings for you in the form of several yaml files.

In my case, I was interested in the docker-compose.override.yml file it added to the project. Out of the box, it looks something like this:

version: '3.4'

services:
  coreapp:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80"

The ports: = "80" bit is what interests us. Change it to "<your desired port>:80" to specify a port to use:

version: '3.4'

services:
  coreapp:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "8080:80"

4 Comments

Good god does this need more upvotes. This totally solved my issues trying to integrate an app with social media logins (i.e.: static callback URLs).
@EricSondergard how did you solve the issues eventually I am running into Social redirects as well trying to locally debug it
@Jean-Paul Yes, I did. I don't quite remember the exact situation, but I'll link you the project I was working on at the time. Hopefully you find what you need. github.com/esond/blazor-crud
Perhaps, I missed something here, but is this as totally unrelated to the OP's question about where do the ServiceHost and Schema come from? This is talking about ports, which was never asked about. (Which I don't get the comment about needing more upvotes..) And I never did see an answer about where to set the ServiceHost (I want to set it to 0.0.0.0 so it will map the port externally correctly)
0

Create a .env file and assign Scheme and ServiceHost.

Scheme=schemename
ServiceHost=localhost

2 Comments

I am not sure what you mean by .env file. Can you provide a documentation link or a more clear description?
If u r using docker-compose, the root directory will have an .env file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.