asp.net 获取ip的方法
//方法一
HttpContext.Current.Request.UserHostAddress;
//方法二
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
//方法三
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
?
if(Context.Request.ServerVariables["HTTP_VIA"]!=null) // 服務(wù)器, using proxy
{
得到真實(shí)的客戶端地址
ip=Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP.
}
else//如果沒有使用代理服務(wù)器或者得不到客戶端的ip not using proxy or can't get the Client IP
{
得到服務(wù)端的地址
ip=Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
}
轉(zhuǎn)載于:https://www.cnblogs.com/weloglog888/archive/2012/11/01/2749176.html
總結(jié)
以上是生活随笔為你收集整理的asp.net 获取ip的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL:将查询结果插入到另一个表的三种情
- 下一篇: asp.net ajax控件工具集 Au