Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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
C# ASP.NET核心:未加载hosting.json URL_C#_Asp.net_.net Core - Fatal编程技术网

C# ASP.NET核心:未加载hosting.json URL

C# ASP.NET核心:未加载hosting.json URL,c#,asp.net,.net-core,C#,Asp.net,.net Core,我试图用hosting.json文件手动覆盖服务器url,但是从未使用过url。我在.NETCore2.0上 hosting.json: { "urls": "http://localhost:5000" } Program.cs: public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static

我试图用
hosting.json
文件手动覆盖服务器url,但是从未使用过url。我在.NETCore2.0上

hosting.json:

{
  "urls": "http://localhost:5000"
}
Program.cs:

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args)
    {
        IConfigurationRoot config = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("hosting.json", optional: true)
            .AddCommandLine(args)
            .Build();

        return WebHost.CreateDefaultBuilder(args)
            .UseConfiguration(config)
            .UseStartup<Startup>()
            .Build();
    }
}
公共类程序
{
公共静态void Main(字符串[]args)
{
BuildWebHost(args.Run();
}
公共静态IWebHost BuildWebHost(字符串[]args)
{
IConfigurationRoot config=new ConfigurationBuilder()
.SetBasePath(目录.GetCurrentDirectory())
.AddJsonFile(“hosting.json”,可选:true)
.AddCommandLine(args)
.Build();
返回WebHost.CreateDefaultBuilder(args)
.UseConfiguration(配置)
.UseStartup()
.Build();
}
}

Visual Studio为您提供了两个运行应用程序的配置文件: IIS Express,它显然使用IIS Express和 WebApplication2(或应用程序的任何给定名称),web项目的名称,该项目使用dotnet运行应用程序,并使用Kastrel而不是IIS运行。 您可以尝试从第二个配置文件切换并运行应用程序(它应该选择hosting.config)

如果要在IIS上运行应用程序,可以更改位于项目属性下的launchSettings.json

此外,您还可以找到有关如何配置URL的更多详细信息