如何获取服务器IP地址(在C#/asp.net中)?
问题描述:
是否有1行方法来获取服务器的IP地址?
Is there a 1 line method to get the IP Address of the server?
谢谢
答
Request.ServerVariables["LOCAL_ADDR"];
从文档:
返回请求所在的服务器地址.这对于计算机上可能有多个IP地址绑定到计算机,并且您想找出请求所使用的地址,这一点很重要.
Returns the server address on which the request came in. This is important on computers where there can be multiple IP addresses bound to the computer, and you want to find out which address the request used.
这不同于与客户端计算机有关的远程地址.
This is distinct from the Remote addresses which relate to the client machine.