c#实现根据网络IP显示地理位置功能示例(2)


Code highlighting produced by Actipro CodeHighlighter (freeware)> 1 using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
namespace AjaxIP
{
/// <summary>
/// IP查询 的摘要说明
/// </summary>
public class IPSearch : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string ip = context.Request["ip"];
string ipFilePath = @"\App_Data\QQWry.dat";
QQWryLocator QQWry = new QQWryLocator(ipFilePath);
IPLocation loc = QQWry.Query(ip);
context.Response.Write(string.Format("{0} {1}",loc.Country,loc.Local));
}
public bool IsReusable
{
get
{
return false;
}
}
}
}


最后在Default.aspx页面写下,js和有IP的用户信息,如下:

复制代码 代码如下:


Code highlighting produced by Actipro CodeHighlighter (freeware)> 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" src="https://www.jb51.net/Js/jquery-1.3.1.js"></script>
<script language="javascript">
$(document).ready(function() {
$("#tb tr").each(function() {
var obj = $(this).children("td:eq(2)");
SearchIP(obj);
});
})
function SearchIP(obj) {
$.ajax({
type: "GET",
url: "IPSearch.ashx?ip=" + obj.text(),
success: function(data) {
obj.text(data);
}
});
}
</script>
</head>
<body>
<form runat="server">
<div>
<table>
<thead>
<th>321321</th>
<th>321321</th>
<th>321321</th>
</thead>
<tr>
<td>
OMEGA</td>
<td>
0</td>
<td>
122.229.191.8</td>
</tr>
<tr>
<td>
荒年</td>
<td>
900,000</td>
<td>
110.87.98.30</td>
</tr>
<tr>
<td>
寒妃</td>
<td>
1,854,257,979</td>
<td>
220.188.193.72</td>
</tr>
<tr>
<td>
哈小土</td>
<td>
600,100</td>
<td>
220.188.193.72</td>
</tr>
<tr>
<td>
化妆造型</td>
<td>
400,100</td>
<td>
220.188.193.72</td>
</tr>
</table>
</div>
</form>
</body>
</html>


这样我们的后台用户信息不再是不友好的IP地址段了。
运行一下,看看效果吧.

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgjgx.html