在 ASP.NET 中获取服务器的 IP 地址? [英] Getting the IP address of server in ASP.NET?
本文介绍了在 ASP.NET 中获取服务器的 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取调用我的 ASP.NET 页面的服务器的 IP 地址?我看过有关 Response 对象的内容,但我对 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-get-the-visitors-IP-address.html
这篇关于在 ASP.NET 中获取服务器的 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文