确定asp.net核心中的端口 [英] Determine port in asp.net core
本文介绍了确定asp.net核心中的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用asp.net core(Web Api)做一些微服务对于服务发现,我想使用 Consul,我必须通过 HTTP API 注册服务,包括 IP 和端口.
I want to make some microservices with asp.net core (Web Api) For service discovery I want use Consul where I must register the services via the HTTP API including IP and port.
我的问题是:我如何知道服务中使用了哪个端口?有没有办法通过代码确定使用的端口?
My question is: How can I know which port is used within in a service? Is there a way to determine the used port via code?
推荐答案
是的,使用 HttpContext.Connection.LocalPort
获取服务器正在监听的本地端口.
Yeah, Use HttpContext.Connection.LocalPort
to get the local port that the server is listening on.
这篇关于确定asp.net核心中的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文