2017-10-07 79 views
1

我想用hosting.json文件手動覆蓋服務器網址,但是網址永遠不會被使用。我在.net核心2.0。ASP.NET核心:hosting.json網址未加載

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(); 
    } 
} 

回答

1

的Visual Studio提供了兩種配置文件來運行應用程序: IIS Express中,其中相當明顯運行使用IIS Express和應用 WebApplication2(或您的應用程序的任何給定名稱)是使用dotnet運行應用程序而不是使用Kastrel運行應用程序的Web項目的名稱。 您可以嘗試從第二個配置文件切換並運行應用程序(它應該選擇hosting.config)。

switching

如果你想運行在IIS上的應用程序,你可以改變launchSettings.json是根據項目屬性位於

IIS

此外,您還可以找到更多的細節如何配置網址here