开发者

How to get the client IP address from the request made to webservice

开发者 https://www.devze.com 2023-03-26 10:08 出处:网络
I have a webservice hosted in my IIS... I need to find out the clientIP address when the client use my service d开发者_开发百科irectly

I have a webservice hosted in my IIS... I need to find out the clientIP address when the client use my service d开发者_开发百科irectly

like http://MyIpAddress/MyApplication/MyWebServiceClass.asmx

and is it possible to read file from the client machine? If so how can I do it?


You should have a plain old HTTP Context at your disposal in ASMX:

        HttpContext.Current.Request.UserHostAddress

Also re: "Is it possible to read a file from the client machine" - this all depends on your implementation. If you're making a web service for your intranet and you work in a small(ish) business environment, you probably can given the proper planning w/ your network guy (not advocating this as a good idea, just a possibility).

To further elaborate, if you are in your small office environment and you get a request from 192.168.1.55 and you know that every client machine in your network has a lastLoginData.txt file in the C drive, AND you have the appropriate configurations for UNC access to the client by the machine hosting the service, getting at "\\" + ip + "\c$\lastLoginData.txt" would be possible. You'd be creating a potentially horrible security issue for yourself, but it'd be possible.

In most normal cicumstances though, no, you will not have access to client disk from the Web Service - some sort of upload will likely have to occur first.


Try calling

Request.UserHostAddress

HttpRequest.UserHostAddress Property

With regards to accessing a file from the client, this would need be achieved by first uploading the file to the server.

Checkout the following on uploading files to a web service:

ASMX file upload

Create a simple file transfer Web service with .NET


        String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (string.IsNullOrEmpty(ip))
        {
            ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        }
        else
        {
            ip=ip.Split(',')[0];
        }

        return ip;
0

精彩评论

暂无评论...
验证码 换一张
取 消