Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core Asp.NET Core Kestrel未使用主机配置文件_Asp.net Core_Multi Tenant_Kestrel Http Server - Fatal编程技术网

Asp.net core Asp.NET Core Kestrel未使用主机配置文件

Asp.net core Asp.NET Core Kestrel未使用主机配置文件,asp.net-core,multi-tenant,kestrel-http-server,Asp.net Core,Multi Tenant,Kestrel Http Server,我有一个Asp.NET核心项目,该项目旨在成为一个多租户应用程序,但在配置该项目以使用我在hosting.json文件中定义的主机名时遇到了问题。如果我使用UseUrls(),它可以正常工作,但我最终需要这些设置,以便localhost能够被环境变量覆盖。这是我的主要思路: var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory())

我有一个Asp.NET核心项目,该项目旨在成为一个多租户应用程序,但在配置该项目以使用我在hosting.json文件中定义的主机名时遇到了问题。如果我使用UseUrls(),它可以正常工作,但我最终需要这些设置,以便localhost能够被环境变量覆盖。这是我的主要思路:

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();
如果启动项目,它只侦听在项目属性的调试部分中定义的应用程序Url。我不确定出了什么问题


我曾经说到这一点。

url仅在控制台应用程序中托管ASP.NET核心项目(通过Kestrel)时有效,而不是在IIS或IISExpress中运行时有效。在后一种情况下(IISExpress),它从解决方案中的.vs/config/applicationhost.config读取它。我正在控制台应用程序中运行它,而不是IIS。您是否通过
将hosting.json复制到构建目录?我不确定这意味着什么。在您的项目的csproj(或
“buildOptions”{“copytooutput”):[…]
在project.json中)。默认情况下,解决方案内部的数据不会复制到build(bin/debug/xxx)目录。但当应用程序运行时,它会在那里搜索。因此,您需要向构建管道中添加说明,以便将此文件复制到那里。
{
  "server.urls": "http://localhost:5000;http://localhost:5001"
}