locked
dont show ipadreess my website RRS feed

  • Question

  • User1928394251 posted

    hello. i write my website with mvc . i run dns server on windows server 2019.i put my website on iis server .my wevsite access on clients local network with host name server .it work good but it dont show ip address client on network .it show mac address client  on network .

    i use this code :

    my controller:

    public ActionResult GetIpWeb()
            {
                string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(ipAddress))
                {
                    ipAddress = Request.ServerVariables["REMOTE_ADDR"];
                }
                ViewBag.IPAddress = ipAddress;

                return View();
            }

    my view:

    @{Html.RenderAction("GetIpWeb", "Home");}

    ip client show in chrom but dont show in ie , mozilla after install , config dns server on windows server 2019.

    i put this my web site on my system with windows10 ,it shows ip client on them of browser.

    i dont know how fix it .

    thanks

    Tuesday, January 12, 2021 6:52 AM

All replies

  • User-474980206 posted

    You network is using ipv6 addresses.

    Tuesday, January 12, 2021 3:22 PM
  • User1928394251 posted

    hello

    thanks you

    my network use ipv4

    Wednesday, January 13, 2021 7:20 AM
  • User753101303 posted

    Hi,

    Try perhaps ipconfig /all on the command line and double check that you really don't see any IPv6 address.

    Your code DOES read the relevant information so more likkely IPv6 is used at least on the last machine that forwaded the request to your web server.

    Or the view doesn't show what youj think?

    Wednesday, January 13, 2021 10:24 AM
  • User1928394251 posted

    hello

    thank for your answer

    my webpage open with host name in chrom , it shows ip client but it dont show on mozilla and ie

    my webpage open with ip address  show ip clients  on all of them browsers ....

    Sunday, January 24, 2021 10:51 AM
  • User753101303 posted

    aabedeni056

    it dont show on mozilla and ie

    Always tell what happens ie what is shown by Mozilla or IE?

    I would expect REMOTE_ADDR to always be populated with someting (even if this is not the value you want). Do you mean that you see an IP v4 value for those browsers?

    Edit: while at it what will you do with the IP address? Note that an IP does NOT identitfy a machine (it coould change, multiple machines could be exposed to internet using a single IP) or could be changed woith a VPN.
    Also AFAIK technically speaking a web server doesn't have to know the IP of the first machine  A web server will send the http response to the last machine that forwared the http request and this machine (or some othe rmachine later down the return path) could be the only one to know about the real IP address for the very first machine that sent this request.

    Sunday, January 24, 2021 6:20 PM
  • User1928394251 posted

    hello

    my website writed with asp.net mvc . i put on iis of windoes server 2019.i run dns server for host name .

    when i write my host name in chrome : it shows right my website .but in mozilla dont work .

    i write my code for get ipaddress in my website :

    controller :

     public ActionResult GetIpWeb()
            {
                string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(ipAddress))
                {
                    ipAddress = Request.ServerVariables["REMOTE_ADDR"];
                }
                ViewBag.IPAddress = ipAddress;

                return View();
            }

    my view :

     @ViewBag.IPAddress

    when run my website without  host name and with ipaddress   server : it right work . (mozilla,chrome , ie )

    Sunday, January 31, 2021 10:58 AM
  • User475983607 posted

    You misunderstand MVC fundamentals.  Controller code runs on the server not in the browser.  There has to be somehting else causing the problem.   Maybe the browser cached the page?  Try pressing ctrl-F5 in the browser to force a refresh.  Or maybe you see the loop back address?

    ::1

    Sunday, January 31, 2021 12:23 PM
  • User753101303 posted

    aabedeni056

    dont work

    Once again always tell what actually happens (ie I assume it does NOT just show a "blank" value, which value do you see ?) rather than something such as "it doesn't work".

    My guess is that it works as expected even if this is not what you expect.

    Edit: for example "doesn't work" could apply to seeing an IP v6 in other browsers but an IP v4 in Mozilla (my current guess) ie we have first to guess what you mean with "doesn't work" when you could just told us right away.
    Sometimes one is posting code that "doesn't work" and it means it throws an exception or even doesn't compile etc...

    Instead if you just tell what happens we can skip trying to guess which bad thing you see.

    Sunday, January 31, 2021 3:37 PM
  • User1928394251 posted

    hello ,thanks

    it means that : i use my website on iis in winserver 2019 without dns,i write in browser 192.168.50.136(ip address my server )

    i start dns server on my server , set zones on it,search my website with hostname server in my browser:http:\\webserwer.

    when i use ip in my browser 192.168.50.136 in every client with every browser , in my website  shows ip address client but when search with hostname it show ipaddress client just on chrome , other show mac address with under code :

    in controller :

    public ActionResult GetIpWeb()
            {
                string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (ipAddress==""||ipAddress==null)
                {
                    ipAddress = Request.ServerVariables["REMOTE_ADDR"];
                }
                ViewBag.IPAddress = ipAddress;

                return View();
            }

    in view :  @ViewBag.IPAddress

    Monday, February 1, 2021 4:41 AM
  • User1928394251 posted

    hello thanks

    when run my website from iis  it shows :

    : ::1

    but when search my website with hostname in browser (server or client ) just chrome show ipaddress ckient right , mozzila , ie show me

    fe80::c847:bd70:ccf7:6c87%15

    but when search my website with ipadress server in browser (server or client ) chrome  , mozzila , ie show my ipaddress client exactly right.

    i want show my website with host name server not ipaddress server .

    i dont know.

    Monday, February 1, 2021 4:49 AM
  • User1928394251 posted

    hello , thanks

    my network  work with just ip4 not ipv6 , 192.168.50.136

    it show

    fe80::c847:bd70:ccf7:6c87%15  on browser client , server(mozilla , ie) when search my website with hostname http:\\webserver (chrome shows right)

    when search with ipaddress server in all of browsers shows right

    Monday, February 1, 2021 4:54 AM
  • User753101303 posted

    So Firefox shows an IPv6 address unless you are using an IPv4 address rather than the hostname in the address bar? You could try https://support.mozilla.org/en-US/kb/firefox-cant-load-websites-other-browsers-can#w_ipv6 to disable IPv6 support in Firefox and see if it shows the expected IPv4 address.

    AFAIK Windows 10 have IPv6 enabled byu default and I'm not sure it can be entirely disabled. You could try netsh interface ipv6 show addresses on the command line to show them and one could match what Firefox shows.

    Now I would never depend on that. The IP address should be taken as an information and is not intended to uniquely identity a machine if this your intent in trying that much to have the same IPv4 value for all browsers.

    Edit: you may want to see https://superuser.com/questions/99746/why-is-there-a-percent-sign-in-the-ipv6-address. This is REALLY an IPv6 address.

    Monday, February 1, 2021 9:48 AM
  • User475983607 posted

    As far as I can gather from you responses.  The code works as expected.  Your complaint is Mozilla Firefox uses FE80::.

    FE80::  is a local address and only resolves in the local network.  I recommend visiting a networking forum for assistance.  

    Also keep in mind, IP addresses are usually meaningless in web applications.  My best guess is you are using the code for testing???  You should use a network sniffer to see what's happening on the network not a web application.

    Monday, February 1, 2021 2:12 PM