问题描述
我建造了一座ASMX服务,并在代码处理来自ELMAH错误日志。
我加入到数据库中的所有领域,我想补充更多一些,一个是请求的客户端...
I builded a ASMX Service and in the code that process an Error Log that comes from ELMAH.I add into the database all the fields and I add some more, one is the IP Address of the requested client...
的IP地址,但我不能(请读,不知道如何)得到...
But I can't (please read, don't know how to) get that...
我已经习惯了。
string ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipAddress == "") ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
不过关,当然这里并不适用,因为它不是一个HTML请求,但SOAP请求
But off course here it does not apply because it's not an HTML request but a SOAP request
在ALL_HTTP头我得到的所有信息:
in ALL_HTTP header I get all this information:
HTTP_CONNECTION:Keep-Alive
HTTP_CONTENT_LENGTH:440331
HTTP_CONTENT_TYPE:text/xml; charset=utf-8
HTTP_EXPECT:100-continue
HTTP_HOST:www.mydomainname.com
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3074)
HTTP_VSDEBUGGERCAUSALITYDATA:uIDPowJ7s0UYlmhEqcDjxYQT/TQAAAAADlaOOkJ5DUizA7gKLg3YEPur8pFWlaVFmpinSAOBTuIACQAA
HTTP_SOAPACTION:"http://www. mydomainname.com/webservices/ErrorReportService/ReportErrors"
在哪里,我怎么能得到所要求的IP?
Where and how can I get the Requested IP?
请注意。 ..:)
推荐答案
您应该能够使用HttpContext.Current.Request.UserHostAddress,但是这不会是可靠的,如果提出请求的机器是使用代理服务器或NAT设备。你会得到代理服务器而不是地址。
You should be able to use HttpContext.Current.Request.UserHostAddress, but this will not be reliable if the requesting machine is behind a proxy server or NAT device. You'll get the address of the proxy server instead.
我想打明确 - 一个IP地址不是适当的唯一标识符。它不识别计算机。在最好的,它确定了一个特定的计算机上的一个特定的网络接口在一个特定的时间使用网络层地址。在不同的时间,同样的网络接口可以是使用不同的IP地址。在不同的时间点,在同一计算机可能具有多于一个的网络接口。你就不能告诉。
I want to make it clear - an IP address is not an appropriate unique identifier. It does not identify a computer. At best, it identifies the Network Layer address that one particular network interface on one particular computer is using at one particular time. At a different time, that same network interface could be using a different IP address. At a different point in time, that same computer might have more than one network interface. You just can't tell.
我似乎记得读取的TCP / IP协议的设计者故意做出明确表示,一个IP地址不能被用作唯一一个计算机的标识符。不幸的是,它似乎太少人阅读。
I seem to remember reading that the designers of the TCP/IP protocols deliberately made it clear that an IP address cannot be used as a unique identifier of a computer. Unfortunately, it seems too few people have read that.
这篇关于获取请求的客户端(SOAP消息)的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!