0

I needed to get the IP address of my Asp.Net server. I mean the IP of the machine that have the IIS when my Asp.Net application is running.

So I googled and found this: [Stackoverflow] Getting the IP address of server in ASP.NET?

And got this code:

var hostName = System.Net.Dns.GetHostName();
var address = System.Net.Dns.GetHostEntry(hostName).AddressList.First().ToString();

Good. It works perfectly, but only in development and test environment. In homologation environment the variable hostName gets correct value, but the address gets: "::1".

It's a super weirdo string. I can't even guess what is happening.

Can someone tell me what I'm doing wrong or what I'm not seen?

Community
  • 1
  • 1
Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81
  • 1
    about [::1](http://stackoverflow.com/a/4611421/815938) – kennyzx Feb 03 '15 at 14:30
  • Did you try the `Request.ServerVariables["LOCAL_ADDR"];` method in the question you linked to? If the question has multiple answers, make sure to look at all of them to see if one is more appropriate for your use case. Only if none of them are appropriate should you ask a new question, and you should address why the existing answers didn't meet your needs. – mason Feb 03 '15 at 14:36
  • I'm running this code in Aplication Start, so Request is null. (Getting from HttpContext.Current). I will try look all items in AddressList. – Jonny Piazzi Feb 03 '15 at 14:43
  • Web servers don't necessarily know their public IP because they may be behind one or more routers (especially production servers). Are you looking for the IP of the IIS site, or the *public* IP that may will in a browser (assuming you are not using host headers)? – NightOwl888 Feb 03 '15 at 19:44
  • I'm looking for the IP of the IIS site. – Jonny Piazzi Feb 03 '15 at 19:48

0 Answers0