Asp.net Core中的UserHostAddress [英] UserHostAddress in Asp.net Core

查看:462
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆