Retrieving clients ip adress on the server

J

Jason Wager

Hello,

I have looked a lot but not found how to do this:

I have a Web Services server and from this I want to see what IP adress the
Client (that connects to the SOAP server) has.
I want to do two things:
1) Restrict access to some specific IP adresses
2) Give different answers the different (allowed) IP adresses.

I don't know how to do either.

The first one, I suspect can be done with configuration.
The second one I need to be able to do from the code. That is, I hope that
there is a function that I can call, which tell me what IP adress the caller
has.
Otherwise, if someone can tell me how to look at the SOAP request as a low
level XML file in .NET (C# or VB.NET), I can find the answer for myself.

Thanks in advance
Jason
 
S

Saurabh Nandu

hi,

You can get the IP Address from the Request object within a Web Method.

As far as restricting IP's you could configure that directly in IIS manager,
this way the restricted IP's will never be able to call your web service.
Although I belive you need to be running a Server OS to enable IP
restrictions.

For the second part i.e. giving different responses based on the client's IP
can be solved by various methods.

1) In code check the IP address can then have switch statements to send back
different messages.
2) You could write your own HttpHandler that can invoke differernt methods
if required to provide differernt responses.

Regards,
Saurabh Nandu
[ MVP | Author ]
 
J

Jason Wager

Thank you for the reply.

Could you give me an example of this - perhaps including which classes that
are needed (Using ....).
I have tried looking at the documentation and all that I find are client
side functions for retrieving information from the server.

Thanks you again,
Jason
 
M

Manni

Just use
Context.Request.UserHostAddress



HTH

Manfred


Jason Wager said:
Thank you for the reply.

Could you give me an example of this - perhaps including which classes that
are needed (Using ....).
I have tried looking at the documentation and all that I find are client
side functions for retrieving information from the server.

Thanks you again,
Jason
You can get the IP Address from the Request object within a Web Method.

Regards,
Saurabh Nandu
[ MVP | Author ]
 
M

Manni

Of course there is a differenc :)

Your code needs to use a textbase indexer
wich means searching somewhere to get an element of an array by
compareing text
and retrieves this "HTTP HEADER" value.

My code uses things CF had loaded to the elements of the Request object.
But since this is a porperty and I don't know the source this could
a.) be a call to some code simmilar to yours
b.) allways be loaded at initialisation of the page

So my code I think will be a little bit faster - espacially if they used B.

Otherwise - if find dealing with that object's property is better readable!

BUT: the value must be the same!!!

Manfred


Jason Wager said:
Thanks

I ended up using
Context.Request.ServerVariables["REMOTE_ADDR"]
I do not know if there is any difference between the two - they return the
same, it seems to me.

Another one just pointed me to this URL, which showed me the above code
http://www.dotnet101.com/articles/art033_servervars.asp

Regards,
Jason


Manni said:
Just use
Context.Request.UserHostAddress



HTH

Manfred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top