当前位置:首页 > ASP教程 > ASP类

asp .net mvc 获得用户IP

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

示例代码

https://github.com/zLulus/NotePractice/blob/dev3/Website/DotNetFramework/NotePractice/Controllers/ClientInfoController.cs

参考资料

https://www.c-sharpcorner.com/uploadfile/krishnasarala/find-client-ip-address-and-location-in-Asp-Net/


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!