确定asp.net核心中的端口 [英] Determine port in asp.net core
本文介绍了确定asp.net核心中的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用asp.net核心(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屋!
查看全文