asp .net mvc 得到用户IP

string strHostName = System.Net.Dns.GetHostName();
//clientIPAddress是一个数组,可能有多个数据
var clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName);
string clientip = clientIPAddress.GetValue(0).ToString();

示例代码

示例代码git

参考资料

Find Client IP Address And Location in ASP.NETgithub

相关文章
相关标签/搜索