简体   繁体   English

ASP.NET Core:hosting.json urls 未加载

[英]ASP.NET Core: hosting.json urls not loaded

I am trying to override the server url manually with a hosting.json file, however the url never get's used.我正在尝试使用hosting.json文件手动覆盖服务器 url,但是从未使用过该 url。 I am on .net core 2.0.我在 .net core 2.0 上。

hosting.json:托管.json:

{
  "urls": "http://localhost:5000"
}

Program.cs:程序.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();
    }
}

Visual Studio gives you two profiles to run application: IIS Express, which fairly obviously runs the application using IIS Express and WebApplication2 (or any given name of your app), the name of the web project, which runs the application using dotnet run using Kastrel instead of IIS. Visual Studio 为您提供了两个配置文件来运行应用程序:IIS Express,它显然使用 IIS Express 和 WebApplication2(或您的应用程序的任何给定名称)运行应用程序,Web 项目的名称,它使用 dotnet 运行应用程序运行使用 Kastrel而不是 IIS。 You can try switching and running application from the second profile (it should pick up hosting.config).您可以尝试从第二个配置文件切换和运行应用程序(它应该选择 hosts.config)。

交换

If you want to run app on IIS you can change launchSettings.json that is located under project properties如果您想在 IIS 上运行应用程序,您可以更改位于项目属性下的 launchSettings.json

信息系统

Also, you can find more details how to configure urls here .此外,您可以在此处找到有关如何配置 url 的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM