Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2003

Tip: Looking for answers? Try searching our database.

Retrieving clients ip adress on the server

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Wager - 20 Nov 2003 17:19 GMT
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
Saurabh Nandu - 21 Nov 2003 05:52 GMT
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 ]
Jason Wager - 21 Nov 2003 08:01 GMT
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 ]
Manni - 21 Nov 2003 09:59 GMT
Just use
Context.Request.UserHostAddress

HTH

Manfred

> Thank you for the reply.
>
[quoted text clipped - 11 lines]
> > Saurabh Nandu
> > [ MVP | Author ]
Jason Wager - 21 Nov 2003 12:24 GMT
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

> Just use
> Context.Request.UserHostAddress
>
> HTH
>
> Manfred
Manni - 21 Nov 2003 18:46 GMT
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

> Thanks
>
[quoted text clipped - 15 lines]
> >
> > Manfred

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.