如何获取调用ASP.NET页的服务器的IP地址?我已经看到了有关Response对象的内容,但是在C#中还是很新的东西。万分感谢。

最佳答案

这应该工作:

 //this gets the ip address of the server pc

  public string GetIPAddress()
  {
     IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // `Dns.Resolve()` method is deprecated.
     IPAddress ipAddress = ipHostInfo.AddressList[0];

     return ipAddress.ToString();
  }

http://wec-library.blogspot.com/2008/03/gets-ip-address-of-server-pc-using-c.html

要么
 //while this gets the ip address of the visitor making the call
  HttpContext.Current.Request.UserHostAddress;

http://www.geekpedia.com/KB32_How-do-I-get-the-visitors-IP-address.html

关于c# - 获取ASP.NET中服务器的IP地址?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/646525/

10-09 18:13
查看更多