0

I have an Asp.NET Core project that is intended to be a multi-tenant application, but I'm having trouble configuring the project to use the host names I define in a hosting.json file. It works fine if I use UseUrls(), but I eventually need these settings for localhost to be able to be overwritten by environment variables. This is what's going on in my main thread:

var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build();

var host = new WebHostBuilder()
    .UseConfiguration(config)
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseKestrel()
    .UseIISIntegration()
    .UseStartup<Startup>()
    //.UseApplicationInsights()
    .Build();

host.Run();

And my hosting.json file:

{
  "server.urls": "http://localhost:5000;http://localhost:5001"
}

If I start the project, it only listens on the App Url defined in the debug section of project properties. I'm not sure what's going wrong.

I used this tutorial to get to this point.

Mike
  • 517
  • 2
  • 5
  • 21
  • The url only works when you host ASP.NET Core project in a console application (via Kestrel), not when you run it in IIS or IISExpress. In later case (IISExpress), it reads it from the .vs/config/applicationhost.config in your solution folder – Tseng Mar 19 '17 at 01:57
  • I am running it in a console application, not IIS. – Mike Mar 19 '17 at 02:17
  • Do you copy over the hosting.json to your build directory via `` ? – Tseng Mar 19 '17 at 03:02
  • I'm not sure what that means. – Mike Mar 20 '17 at 01:55
  • Inside your project's csproj (or `"buildOptions" { "copyToToOutput" : [ ...] }` in project.json). By default inside the solution are not copied over to the build (bin/debug/xxx) directory. But when your application runs it searches it there. So you need to add instructions to the build pipeline to copy this file there. – Tseng Mar 20 '17 at 07:10
  • I don't see that anywhere in the csproj file. How do I change the build pipeline? – Mike Mar 22 '17 at 20:38

0 Answers0