C#中获取用户登录IP地址

using System.Net; //导入命名空间

public string getLocalIP()
{
string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
string strAddr = ipEntry.AddressList[0].ToString();
return (strAddr);
}

//用法
if (rs.HasRows)
{
rs.Read();
context.Session["DLUserID"] = rs["U_UserID"].ToString();
context.Session["DLgetdate"] = rs["getdate"].ToString();

context.Session["DLUserDate"] = rs["U_Date"].ToString();
context.Session["DLUserIP"] = getLocalIP();
context.Response.Redirect("index_Main.aspx?Dl=" + rs["U_UserID"].ToString() + "&pas=" + rs["U_Pass"].ToString() + "");
rs.Close();
}
else
{
context.Response.Redirect("login.aspx");
}

//获取登录ip

public string getLocalIP()
{
string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
string strAddr = ipEntry.AddressList[0].ToString();
return (strAddr);
}

public bool IsReusable
{
get
{
return false;
}
}
}


原文:http://www.cnblogs.com/liujieblogs/p/6901279.html
原文地址:https://www.cnblogs.com/Tianxf815/p/10949252.html