Asp.net Core中的UserHostAddress [英] UserHostAddress in Asp.net Core
本文介绍了Asp.net Core中的UserHostAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
旧版HttpContext.Request.UserHostAddress
的Asp.Net Core中的等效项是什么?
What is the equivalent in Asp.Net Core of the old HttpContext.Request.UserHostAddress
?
我尝试了this.ActionContext.HttpContext
,但是找不到UserHostAddress或ServerVariables属性.
I tried this.ActionContext.HttpContext
but cannot find the UserHostAddress nor the ServerVariables properties.
谢谢
推荐答案
如果可以访问HttpContext
,则可以通过Connection
属性获取本地/远程IpAddress,如下所示:
If you have access to the HttpContext
, you can get the Local/Remote IpAddress from the Connection
property like so:
var remote = this.HttpContext.Connection.RemoteIpAddress;
var local = this.HttpContext.Connection.LocalIpAddress;
这篇关于Asp.net Core中的UserHostAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文