How to get a user's client IP address in ASP.NET?

前端 未结 19 2557
时光取名叫无心
时光取名叫无心 2020-11-22 00:26

We have Request.UserHostAddress to get the IP address in ASP.NET, but this is usually the user\'s ISP\'s IP address, not exactly the user\'s machine IP address

19条回答
  •  粉色の甜心
    2020-11-22 00:48

    If is c# see this way, is very simple

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

提交回复
热议问题