引用IP地址 [英] Referring IP Address

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

问题描述

是否有一种简单的方法来获取引荐服务器的IP地址,方法类似于

Is there an easy way to get the IP Address of the referring server in a similar way to

strReferer = HttpContext.Current.Request.UrlReferrer.ToString();

推荐答案

获取托管应用程序服务器的IP地址.

To get IP Address of Server of your Hosted application.

string hostName = System.Net.Dns.GetHostName();
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName);
IPAddress ipDetails = ipHostInfo.AddressList[0];
string ipAddress = ipDetails.ToString();


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"];


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

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