I have developed a web service and host it on my server and I would like to know who is using this web service (site Url). I tryed to use "Request.UrlReferrer" but it is not returning any thing! any suggestions/Advices?
我已经开发了一个Web服务并将其托管在我的服务器上,我想知道谁在使用这个Web服务(站点Url)。我尝试使用“Request.UrlReferrer”,但它没有返回任何东西!任何建议/意见?
4 个解决方案
#1
You can't get the URL of the caller of a web service as not all callers have canonical URL's. You can however get the IP Addresses assuming that they are not behind a proxy / nat. In which case you'd get the IP of the nat / proxy.
您无法获取Web服务调用者的URL,因为并非所有调用者都具有规范URL。但是,您可以获取IP地址,假设它们不在代理/ nat之后。在这种情况下,您将获得nat / proxy的IP。
Assuming your using an ASMX web service you can this from:
假设您使用ASMX Web服务,您可以:
HttpContext.Current.Request.UserHostAddress
Once you have the IP Address you can try and do a reverse lookup to get the host name. I would recommend storing the IP address then writting an offline process which goes and tries to determine who owns the IP. I'm sure there are some webservices out there to help with this.
获得IP地址后,您可以尝试进行反向查找以获取主机名。我建议存储IP地址,然后写一个离线进程,然后尝试确定谁拥有IP。我确信有一些网络服务可以帮助解决这个问题。
#2
You can use Request.Url property to get all the information about the requests to your web service.
您可以使用Request.Url属性获取有关Web服务请求的所有信息。
#3
The referrer is set by the client, and the client can not set it. That is why you see nothing. If the client's are servers, then the best you can do is to get the IP of the client connection and go to that IP. If a simple setup, with no virtual hosts, then that is the "web site" that is hitting your web service.
引用者由客户端设置,客户端无法设置它。这就是你什么也看不见的原因。如果客户端是服务器,那么您可以做的最好的事情是获取客户端连接的IP并转到该IP。如果是一个简单的设置,没有虚拟主机,那么就是那个正在点击你的web服务的“网站”。
#4
As Josh states, the HttpRequest object is the way to go, there are a few properties on there that might help:
正如Josh所说,HttpRequest对象是可行的方法,那里有一些可能有用的属性:
- UserHostName - Gets the DNS name of the remote client.
- UserAgent - Gets the raw user agent string of the client browser.
- UserHostAddress - Gets the IP host address of the remote client.
UserHostName - 获取远程客户端的DNS名称。
UserAgent - 获取客户端浏览器的原始用户代理字符串。
UserHostAddress - 获取远程客户端的IP主机地址。
Which might give you a bit more information to play with.
这可能会为您提供更多信息。
#1
You can't get the URL of the caller of a web service as not all callers have canonical URL's. You can however get the IP Addresses assuming that they are not behind a proxy / nat. In which case you'd get the IP of the nat / proxy.
您无法获取Web服务调用者的URL,因为并非所有调用者都具有规范URL。但是,您可以获取IP地址,假设它们不在代理/ nat之后。在这种情况下,您将获得nat / proxy的IP。
Assuming your using an ASMX web service you can this from:
假设您使用ASMX Web服务,您可以:
HttpContext.Current.Request.UserHostAddress
Once you have the IP Address you can try and do a reverse lookup to get the host name. I would recommend storing the IP address then writting an offline process which goes and tries to determine who owns the IP. I'm sure there are some webservices out there to help with this.
获得IP地址后,您可以尝试进行反向查找以获取主机名。我建议存储IP地址,然后写一个离线进程,然后尝试确定谁拥有IP。我确信有一些网络服务可以帮助解决这个问题。
#2
You can use Request.Url property to get all the information about the requests to your web service.
您可以使用Request.Url属性获取有关Web服务请求的所有信息。
#3
The referrer is set by the client, and the client can not set it. That is why you see nothing. If the client's are servers, then the best you can do is to get the IP of the client connection and go to that IP. If a simple setup, with no virtual hosts, then that is the "web site" that is hitting your web service.
引用者由客户端设置,客户端无法设置它。这就是你什么也看不见的原因。如果客户端是服务器,那么您可以做的最好的事情是获取客户端连接的IP并转到该IP。如果是一个简单的设置,没有虚拟主机,那么就是那个正在点击你的web服务的“网站”。
#4
As Josh states, the HttpRequest object is the way to go, there are a few properties on there that might help:
正如Josh所说,HttpRequest对象是可行的方法,那里有一些可能有用的属性:
- UserHostName - Gets the DNS name of the remote client.
- UserAgent - Gets the raw user agent string of the client browser.
- UserHostAddress - Gets the IP host address of the remote client.
UserHostName - 获取远程客户端的DNS名称。
UserAgent - 获取客户端浏览器的原始用户代理字符串。
UserHostAddress - 获取远程客户端的IP主机地址。
Which might give you a bit more information to play with.
这可能会为您提供更多信息。