Getting client ip address

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi all,

I'm trying to write some code in a business layer which will audit the
IP address that the request is coming from.

If the business layer is being called from a web app, I'd like to get
the IP address of the client browser, but if the business layer is
being called from a desktop app, i'd like to capture the desktop's IP
address.

The catch is that I don't want to have to pass the IP address from the
UI layer into the business layer; the business layer should be able to
detect this automatically.

Any ideas?

Thanks
Andy
 
Dns.Resolve(Dns.GetHostName()).AddressList
This will return all the IP addresses of the machine. I don't know how to
get it from a browser, it's the wrong group for that.

Cheers,
Mark
 
I know how to get it from a browser, so i guess the question is
technically how do i detect if i'm running an IIS process or not, and
if i am running under one, how can i get the HttpContext object.

Andy
 
Andy,

You can do this by checking the static Current property on the
HttpContext class. If there is one, then you will be able to get it here.

However, if you are going to use these objects through remoting, I don't
know that it would be possible to actually get the IP address of the client.
You should have your client objects get the IP address yourself, and then
pass that long with the call.

Hope this helps.
 

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

Back
Top