1

I have a problem to get the user's ip address into web server. I am using this code..

//To get the local IP address 
            string sHostName = Dns.GetHostName();
            IPHostEntry ipE = Dns.GetHostByName(sHostName);
            IPAddress[] IpA = ipE.AddressList;
            for (int i = 0; i < IpA.Length; i++)
            {
                Console.WriteLine("IP Address {0}: {1} ", i, IpA[i].ToString());
                string IPAddress= IpA[i].ToString();//ip;// IPAddress;// strIPAddress;
            }

due to this I am getting user IP address into local host accurate but when I upload my website into web server than it's having all user's ip address same as server IP address... please guys help me.

4 Answers 4

4

That code will get you the IP address of the server.

You can access the user's IP address with this property: Request.UserHostAddress

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

2 Comments

string IPAddress=Request.UserHostAddress; You can use that from the same place you currently have the block of code in your example. If that doesn't work, please let us know the location of that current code you're using.
Exactly thats iP Address of server. Have a look at this article for client ip c-sharpcorner.com/blogs/…
2

Get users IP address

Request.ServerVariables("REMOTE_ADDR")
or
Request.UserHostAddress

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

Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

This link help you more..

http://www.codeproject.com/Questions/260872/How-to-get-client-IP-in-asp-net-Csharp

1 Comment

In Page_Load or any Event function when you can get Request.
0

The code you have used only work in case of windows application (Client server architecture) But to get the users ip address in web application you need to use

Request.UserHostAddress

Comments

0

No matter how hard you try you can only get server IP using server side code in Asp.Net.However the method told in this article will let you access client ip using javascript.refer this https://www.c-sharpcorner.com/blogs/getting-client-ip-address-or-local-ip-address-in-javascript

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.