Skip to content

asp .net mvc 获得用户IP

L edited this page Oct 4, 2018 · 2 revisions
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/

Clone this wiki locally