1) First Way to get the client Ip Address in asp.net with C#
string ip;
ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
string trueIP = ipRange[le];
}
else
{
ip = Request.ServerVariables["REMOTE_ADDR"];
}
Response.Write(ip);
Response.Write(Request.UserHostAddress);
2)Second Way to Get the client up address in asp.net with C#
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
Response.Write(clientIPAddress);
No comments:
Post a Comment