Preview中的appsettings

Preview中的appsettings

本文介绍了我可以在ASP.net Core 2.0 Preview中的appsettings.json中设置侦听URL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个ASP.net Core 2.0应用程序,以在.net Core 2.0运行时上运行,它们当前均处于预览版。但是,我无法弄清楚如何让Kestrel使用默认的 http:// localhost:5000 监听URL以外的东西。

I'm creating an ASP.net Core 2.0 app to run on the .net Core 2.0 runtime, both currently in their Preview versions. However, I cannot figure out how to have Kestrel use something other than the default http://localhost:5000 listen URL.

我可以让Google谈论的大多数文档有关 server.urls 设置,即使在1.0预览版中,该设置似乎也已更改为 urls ,但是都不起作用(打开Debug日志时,Kestrel告诉我未配置任何侦听端点)。

Most documentation that I could Google talks about a server.urls setting, which seems to have been changed even in 1.0-preview to just be urls, however neither works (turning on Debug logging has Kestrel telling me that no listen endpoints are configured).

也有很多文档谈到 hosting.json ,我不能使用默认的appsettings.json。但是,如果我比较推荐的加载新配置的方法,则看起来与新的方法可以,但它会加载appsettings.json。

A lot of documentation also talks about a hosting.json and that I can't use the default appsettings.json. However, if I compare the recommended approach of loading a new config, this looks pretty much exactly like what the new WebHost.CreateDefaultBuilder method does, except that it loads appsettings.json.

我目前不了解appsettings.json和 IConfigureOptions< T> 是如何关联的,所以很可能会引起我的麻烦由于缺乏对实际上可以。

I currently don't understand how appsettings.json and IConfigureOptions<T> are related, if at all, so it's possible that my trouble stems from a lack of understanding of what KestrelServerOptionsSetup actually does.

推荐答案

public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseConfiguration(new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("hosting.json", optional: true)
                .Build()
            )
            .UseStartup<Startup>()
            .Build();

和hosting.json

And the hosting.json

{ "urls": "http://*:5005;" }

这篇关于我可以在ASP.net Core 2.0 Preview中的appsettings.json中设置侦听URL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:53