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;
}
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM