获取ASP.NET中的服务器的IP地址? [英] Getting the IP address of server in ASP.NET?

查看:129
本文介绍了获取ASP.NET中的服务器的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到我的电话ASP.NET页面的服务器的IP地址?我看到的东西有关响应对象,但我在C#很新。由于一吨。

How do I get the IP address of the server that calls my ASP.NET page? I have seen stuff about a Response object, but am very new at c#. Thanks a ton.

推荐答案

这应该工作:

 //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-得到最游客-IP-address.html

这篇关于获取ASP.NET中的服务器的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆