我可以在 ASP.net Core 2.0 Preview 的 appsettings.json 中设置监听 URL 吗? [英] Can I set listen URLs in appsettings.json in ASP.net Core 2.0 Preview?
问题描述
我正在创建一个 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-preview 中,它似乎也已更改为 urls
,但两者都不起作用(打开调试日志让 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.但是,如果我比较推荐的加载新配置的方法,这看起来非常像新的 WebHost.CreateDefaultBuilder
方法可以,除了它加载 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>
是如何相关的(如果有的话),所以我的问题可能源于对 codeServer/a> 确实如此.
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();
和托管.json
{ "urls": "http://*:5005;" }
这篇关于我可以在 ASP.net Core 2.0 Preview 的 appsettings.json 中设置监听 URL 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!