Retrieving clients ip adress on the server

Discussion in 'ASP .Net Web Services' started by Jason Wager, Nov 20, 2003.

  1. Jason Wager

    Jason Wager Guest

    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
    Jason Wager, Nov 20, 2003
    #1
    1. Advertising

  2. 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 ]
    Saurabh Nandu, Nov 21, 2003
    #2
    1. Advertising

  3. Jason Wager

    Jason Wager Guest

    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 ]
    >
    >
    Jason Wager, Nov 21, 2003
    #3
  4. Jason Wager

    Manni Guest

    Just use
    Context.Request.UserHostAddress



    HTH

    Manfred


    "Jason Wager" <> schrieb im Newsbeitrag
    news:%23%...
    > 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, Nov 21, 2003
    #4
  5. Jason Wager

    Jason Wager Guest

    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" <> skrev i en meddelelse
    news:%...
    > Just use
    > Context.Request.UserHostAddress
    >
    >
    >
    > HTH
    >
    > Manfred
    >
    Jason Wager, Nov 21, 2003
    #5
  6. Jason Wager

    Manni Guest

    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" <> schrieb im Newsbeitrag
    news:...
    > 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" <> skrev i en meddelelse
    > news:%...
    > > Just use
    > > Context.Request.UserHostAddress
    > >
    > >
    > >
    > > HTH
    > >
    > > Manfred
    > >

    >
    >
    Manni, Nov 21, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bk
    Replies:
    0
    Views:
    463
  2. Jarod_24

    adress of server

    Jarod_24, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    306
    Jarod_24
    Apr 2, 2004
  3. Francesco
    Replies:
    1
    Views:
    513
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Dec 27, 2006
  4. hpber
    Replies:
    2
    Views:
    283
    Marcus Kwok
    Jul 5, 2007
  5. Scott Townsend
    Replies:
    5
    Views:
    150
    Ray at
    Jun 4, 2004
Loading...

Share This Page