在asp.net中获取用户IP地址 [英] Get user IP address in asp.net

查看:92
本文介绍了在asp.net中获取用户IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当用户注册到站点时,我想将用户IP地址存储到数据库中.

如何在asp.net中获取客户端IP?

在此先感谢

Hi,

I want to store user IP address into the Database when user register in to the site.

How to get Client IP in asp.net?

Thanks in Advance

推荐答案

HttpContext.Current.Request.UserHostAddress;




or

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];



要获取机器而非代理的IP地址,请使用以下代码



To get the IP address of the machine and not the proxy use the following code

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];


这篇关于在asp.net中获取用户IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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