我可以在ASP.net Core 2.0 Preview中的appsettings.json中设置侦听URL吗?

编程入门 行业动态 更新时间:2024-10-25 03:23:25
本文介绍了我可以在ASP Core 2.0 Preview中的appsettings.json中设置侦听URL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm creating an ASP Core 2.0 app to run on the 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 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。但是,如果我比较推荐的加载新配置的方法,则看起来与新的 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> 是如何关联的,所以很可能会引起我的麻烦由于缺乏对 KestrelServerOptionsSetup 实际上可以。

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": "*:5005;" }

更多推荐

我可以在ASP.net Core 2.0 Preview中的appsettings.json中设置侦听URL吗?

本文发布于:2023-11-15 21:20:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Core   ASP   net   json   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!