Retrieving client user name and computer name from within webservice
I have web service on ser开发者_如何学JAVAver! This service is calling from the clients applications!
Now how i can get user name and computer name of clients that using this service, for example if application from Clint1 calling this service i want to get computer name and user name of Clint1?
Many thanks!
You can't reliably, really.
The server variable REMOTE_HOST
may provide you with it, but in most cases it will be an IP address and it could well be a proxy's IP address. Also - it is something that can be easily spoofed.
Same goes for username (REMOTE_USER
), unless you use some WS-Security
mechanism to authenticate the user calling your webservice.
The client will have to be passing this information to the service.
As Wim said, you can't get this information reliably. For a guaranteed Windows network you can retrieve the current authenticated user (to the machine) using the server variable:
System.Web.HttpContext.Current.Request.ServerVariables("LOGON_USER")
The REMOTE_HOST variable is supposed to return the machine name, but in most cases (as he said) it will only be an IP address.
Even on a LAN, this is not an advisable security practice. This information can still be spoofed locally providing internal users the capability to masquerade as other users. If it's simply being used for identification (rather than authentication or authorization) it would probably be "good enough". If you maintained a small datatable (or the networking team) that identified each pc to its expected IP address, this information would achieve what you want.
精彩评论