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

前端 未结 4 842
攒了一身酷
攒了一身酷 2021-01-15 19:18

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.Get         


        
相关标签:
4条回答
  • 2021-01-15 19:29

    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

    0 讨论(0)
  • 2021-01-15 19:38

    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

    0 讨论(0)
  • 2021-01-15 19:40

    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
    
    0 讨论(0)
  • 2021-01-15 19:42

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

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

    0 讨论(0)
提交回复
热议问题