C#怎么获取留言人IP
来源:百度知道 编辑:UC知道 时间:2024/06/23 13:12:23
using System.Net;
string ipStr = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();// ip地址
Request.UserHostAddress
就是访问者的ip
string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == ip || ip == String.Empty)
{
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == ip || ip == String.Empty)
{
ip = System.Web.HttpContext.Current.Request.UserHostAddress;
}
string ip = "";
if (Context.Request.ServerVariables["HTTP_VIA"] != null)
{
ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]