Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently i am using below code.


private string GetIP()
       {
           string strHostName = "";
           strHostName = System.Net.Dns.GetHostName();

           IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);

           IPAddress[] addr = ipEntry.AddressList;

           return addr[addr.Length - 1].ToString();

       }


in local working fine.In live i am not getting ip address.
I just getting ::1 only..

Please help me to find ip address of user who is accessing my site..

Thanks
Posted

Try this
C#
string clientIp = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
 if( !string.IsNullOrEmpty(clientIp) ) {
  string[] forwardedIps = clientIp.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries );
  clientIp = forwardedIps[forwardedIps.Length - 1];
 } else {
  clientIp = context.Request.ServerVariables["REMOTE_ADDR"];
 }



http://stackoverflow.com/questions/2670004/ip-address-of-the-client-machine[^]
 
Share this answer
 
Comments
venkata chaitanya 29-Aug-12 3:28am    
Thank you working fine
Santhosh Kumar Jayaraman 29-Aug-12 3:28am    
wc
venkata chaitanya 29-Aug-12 4:25am    
Have you ever worked on global.asax file?If you worked on it please answer to my previous question

http://www.codeproject.com/Questions/448145/regarding-session-start-event-in-Global-asax

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