title: How Do You Access the `applicationUrl` Property Found in launchSettings.json from Asp.NET Core 3.1 Startup class?
body: <p>I am currently creating an Asp.NET Core 3.1 API Application.  In it, I have a <code>launchSettings.json</code> that looks like the following:</p>
  
  <pre><code>{
    "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
        "applicationUrl": "http://localhost:61392",
        "sslPort": 44308
      }
    },
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "profiles": {
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "launchUrl": "weatherforecast",
        "environmentVariables": {
          "Key": "Value",
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "Application.API": {
        "commandName": "Project",
        "launchBrowser": true,
        "launchUrl": "weatherforecast",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "applicationUrl": "https://localhost:5001;http://localhost:5000"
      }
    }
  }
  </code></pre>
  
  <p>In particular, I am interested in obtaining the <code>applicationUrl</code> values defined in this file.  Unfortunately, I do not see any obvious way to access them outside of loading the file directly via JSON serialization and probing the values there.</p>
  
  <p>As such, I am looking for a more elegant solution.  Is there a way to access these values from within the <code>Startup.Configure</code> and/or <code>Startup.ConfigureServices</code> methods?</p>
  
  <p>I am thinking of something like:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void Configure(IApplicationBuilder builder)
  {
      var url = builder.ApplicationServices.GetRequiredService&lt;IServerHostingEnvironment&gt;().ApplicationUrl
  }
  </code></pre>
  
  <p>For reference, I did see <a href="https://stackoverflow.com/a/47051481/10340424">this question</a>, but it seems that this requires an HTTP request.  In my case, I am still configuring the server before a request has been made.</p>
  
  <p>For <em>further</em> reference and context:  I am building a .NET GitHub App application, and am making the corresponding equivalent of the Smee.io client, whose Javascript code <a href="https://github.com/probot/smee-client/blob/master/index.js" rel="noreferrer">can be found here</a>.</p>
  
  <p>The client takes a <code>source</code> (via Server-sent events) and sends it to a <code>target</code>.  I got the <code>source</code> figured out and configured, but am ironically having trouble accessing and establishing the <code>target</code> URL (the <code>applicationUrl</code> seen above) in an obvious and configured fashion.</p>
  
  <p>Finally, I realize I could hardcode the value in <code>appSettings.json</code>, but that would then mean I would be maintaining the same value in two places -- one in <code>appSettings.json</code> and one in the already-existing <code>launchSettings.json</code>.  I would rather keep it to one place to reduce maintenance burden, if possible.</p>