System.Web.HttpContext.Current.Request.UserHostAddress;

后端 未结 3 876
独厮守ぢ
独厮守ぢ 2020-12-18 10:05

I am using the following code to obtain the user I.P. address but something strange is happening. I am, receiving the same ip address every time no matter if I am on my desk

3条回答
  •  执念已碎
    2020-12-18 10:32

    Try this;

    if (!String.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"]))
          ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_CLIENT_IP"];
    else
          ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    

    Request.UserHostAddress return server IP which IIS run on.

提交回复
热议问题