5

In my web application i have registration form, when user register i want to get his ip address of his system, how can i get using asp.net. help me please.

3 Answers 3

9
HttpContext.Current.Request.UserHostAddress; 

or

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

To get the IP address of the machine and not the proxy use the following code

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
Sign up to request clarification or add additional context in comments.

2 Comments

@Lance: Good point. More info on that here: en.wikipedia.org/wiki/X-Forwarded-For
than u Mr.Lance Harper it is working but what is the sencond one and third one it is not working
3

HttpContext.Current.Request.UserHostAddress

1 Comment

Do note that for IIS7, Request.UserHostAddress for localhost returns ::1 and not 127.0.0.1.
2

Try:

Request.ServerVariables["REMOTE_ADDR"].ToString() 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.