c# - ASP.NET Core : hosting. 未加载 json url

标签 c# asp.net .net-core

我正在尝试使用 hosting.json 文件手动覆盖服务器 url,但是该 url 从未被使用过。我在 .net 核心 2.0 上。

托管.json:

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

程序.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 为您提供了两个配置文件来运行应用程序: IIS Express,很明显,它使用 IIS Express 运行应用程序,并且 WebApplication2(或您的应用程序的任何给定名称),Web 项目的名称,它使用使用 Kastrel 而不是 IIS 的 dotnet run 运行应用程序。 您可以尝试从第二个配置文件切换和运行应用程序(它应该选择 hosting.config)。

switching

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

IIS

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

关于c# - ASP.NET Core : hosting. 未加载 json url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46625158/

相关文章:

c# - LINQ:具有多个条件的左外连接

c# - 使用带有 lambda 表达式的 linQ 删除记录

c# - 如何在不使用 ping method C# 的情况下使用连接到我的 PC 的机器的 IP 地址

c# - 帮助 Linq 查询

c# - 我希望用户能够下载页面

mysql - Postman 无法接收来自 M 到 N 集合的 JSON

c# - 使用已经运行的应用程序实例

c# - 在 ASP.NET Core 中连接子应用程序

c# - 无法从程序集“Microsoft.Azure.WebJobs.Host”加载类型 'Microsoft.Azure.WebJobs.Host.Scale.ConcurrencyManager'

visual-studio-2015 - xUnit.net v2 未在 Visual Studio 2015 中发现 .NET Core 测试