简体   繁体   中英

how to get the user's ip address on web server?

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.

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

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

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

您使用的代码仅在Windows应用程序(客户端服务器体系结构)下有效,但是要在Web应用程序中获取用户ip地址,您需要使用

Request.UserHostAddress

不管你怎么努力,你只能在Asp.Net.However使用服务器端代码获取服务器IP的方法,在这篇文章中说会让你使用javascript.refer访问客户端IP此https://www.c-sharpcorner.com / blogs / getting-client-ip-address-or-local-ip-address-in-javascript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM