1

This is the label

 <asp:Label ID="lblIp" runat="server"></asp:Label>

Here Code I used to get user IP address

 string VisitorsIPAddr = string.Empty;

            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {

                VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                lblIp.Text = VisitorsIPAddr;
            }
            else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
            {
                VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
                lblIp.Text = VisitorsIPAddr;
            }

but Always I got the same result. That was 127.0.0.1 and always it goes to else if state.

further

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] did not give any result. It always give nothing

2
  • It seems you running this application at local end. Commented Nov 17, 2013 at 5:09
  • I am a student and I have no good knowledge on programming. Could you please explain more ? Commented Nov 17, 2013 at 6:42

1 Answer 1

1

You are running the application at your own machine therefor you are the one sliding there, so you will always get 127.0.0.1 in the else if. If you want to see another IP open the app and relevant port and get there with another machine.

Also the HTTP_X_FORWARDED_FOR is not always there (usually from normal web requests it will be but there are exceptions).

I think thats what Kundan Singh Chouhan tried to suggest, hope I am not wrong.

Sign up to request clarification or add additional context in comments.

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.