Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all

can i get the local system ip address when i am running my asp.net web application on local host

i am getting my result as "IP Address: ::1" is it correct or not


thank's in advance
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jun-13 10:00am    
Not clear what you are getting and how. What is "local"? Client is client, whatever IP of the party which sent HTTP request. What did you try so far?
—SA
ASLAM SYED 4-Jun-13 10:03am    
Local means "Localhost" Client means the user who's is trying to access my web application
Sergey Alexandrovich Kryukov 4-Jun-13 10:09am    
"localhost" is not a "real" IP address. This is a kind of placeholder which you can use in URL. When you actually do an HTTP request, there is always a real address. Anyway, please see my answer.
—SA
ASLAM SYED 4-Jun-13 10:13am    
Thank you for your response
Sergey Alexandrovich Kryukov 4-Jun-13 10:26am    
You are welcome. Will my answer solve your problem? Will you accept it?
—SA

Please see my comment to the question. You can use Request.UserHostAddress:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.userhostaddress.aspx[^]

or Request.ServerVariables("REMOTE_ADDR"):
http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx[^].

This is the list for IIS:
http://msdn.microsoft.com/en-us/library/ms524602.aspx[^].

—SA
 
Share this answer
 
v2
Comments
Thanks7872 6-Jun-13 0:09am    
↑voted...Good One..! I have tried to elaborate lil bit in below answer.
Sergey Alexandrovich Kryukov 6-Jun-13 0:24am    
Thank you, Rohan.
—SA
Thanks7872 6-Jun-13 0:27am    
You are welcome Sergey...
If you try to get ip while running application from localhost you will get something like 127.0.0.1 as said by the experts above.Have a look at the below code.

C#
string ip=Server.HtmlEncode(Request.UserHostAddress);


This line of code,when executed on localhost,will give you something like 127.0.0.1.But suppose you host it on production server,at that time it will give you the actual client ip(in string format),that is the one trying to interact with your web etc.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 6-Jun-13 0:24am    
Thumbs↑, 5ed. :-)
—SA
Thanks7872 6-Jun-13 0:37am    
Thanks alot..!

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