IP address of the user who is browsing my website

后端 未结 4 1290
梦毁少年i
梦毁少年i 2021-01-07 07:59

I want to know the IP address of the client machine, i.e. the IP address of the user who is browsing my website. I am trying the following code but it is returning server ad

4条回答
  •  走了就别回头了
    2021-01-07 08:23

    string myIP = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim();
    

    Note: For getting the public ip address this is used.

提交回复
热议问题