- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ASP.NET Core 2.0 Web 应用程序,我需要在启动期间传递应用程序的 URL,以便集成到其他应用程序中。
在 Visual Studio (IIS Express) 下运行时,IApplicationBuilder.ServerFeatures.Get<IServerAddressesFeature>().Addresses
包含我的应用程序绑定(bind)到的 URL(例如 http://localhost:1234
)。
当使用 dotnet.exe myapp.dll
运行时,同一个集合是空的,但是,我在标准输出上看到一行 Now listening on: http://localhost:5000
.
问题是,要获取 URL,我是否必须解析 dotnet.exe 的输出以获取以 Now listening on:
开头的行? ,或者有没有更不脆弱的方法?
最佳答案
这是由于 2017 年 3 月对 Kestrel 进行的更改所致。来自 announcement :
Hosting no longer adds default server address when no address is explicitly configured
The WebHost will no longer add the default server address of
http://localhost:5000
to theIServerAddressesFeature
when none is specified. The configuration of the default server address will now be a responsibility of the server.Addresses specified in
IServerAddressesFeature
are intended to be used by servers as a fallback when no explicit address is specified directly.
Hosting no longer adds default server address when no address is explicitly configured中有一个如何处理这个问题的例子。 :
If you are implementing a server and rely on the
IServerAddressesFeature
to be set by hosting, that will no longer be set and a default should be added when no address is configured. As an example:var serverFeatures = featureCollection.Get<IServerAddressesFeature>();
if (serverFeatures .Addresses.Count == 0)
{
ListenOn(DefaultAddress); // Start the server on the default address
serverFeatures.Addresses.Add(DefaultAddress) // Add the default address to the IServerAddressesFeature
}
关于asp.net-core - 在 dotnet.exe 下运行时,IServerAddressesFeature 地址为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48546843/
我有一个 ASP.NET Core 2.0 Web 应用程序,我需要在启动期间传递应用程序的 URL,以便集成到其他应用程序中。 在 Visual Studio (IIS Express) 下运行时,
我是一名优秀的程序员,十分优秀!