Click here to Skip to main content
15,917,951 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi All,

Please provide me the code how to get the CLient IP address OR Client System Login from Asp.Net web application, I have tried somoe code from googling, but it not worked out. All are returning Server IP address.

Thanks.
Posted

C#
String ip=Server.HTMLEncode(Request.UserHostAddress);


Put this line where you want the ip address of the system accessing the page.You will get 127.0.0.1 if you try it on localhost.After deployment on server,you will get the system's public ip address as a string.
 
Share this answer
 
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
string ipAddressText = addr[addr.Length - 1].ToString();
 
Share this answer
 
Comments
Manfred Rudolf Bihy 30-Apr-13 9:11am    
This doesn't get the client IP.
SireeshaPhani 30-Apr-13 9:13am    
You are right, It is not giving Client IP address..
SireeshaPhani 30-Apr-13 9:13am    
It is giving Same Server IP Address, Not Client IP address

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900