1 //ashx文件 
 2 
 3 public void ProcessRequest (HttpContext context) {
 4 
 5                      string action=context.Request["action"];
 6 
 7 if (action == "GetIP")
 8 {
 9 string result;
10 result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
11 if (null == result || result == String.Empty)
12 {
13 result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
14 }
15 
16 if (null == result || result == String.Empty)
17 {
18 result = HttpContext.Current.Request.UserHostAddress;
19 }
20 IP ip = IPManager.GetOne("select * from IP where '" + result + "' between IP_Start and IP_End");
21 if (ip.ID > 0)
22 {
23 context.Response.Write(1);
24 }
25 else
26 {
27 context.Response.Write(0);
28 } //取得数据后返回给客户端。
29 
30 }
31 }
32 //html
33 
34 <script type="text/javascript">
35 $(function getIP() {
36 $.post("/ashx/PageNews.ashx", { "action": "GetIP" }, function (data) {
37 var json = eval(data);
38 if (json == "1") {
39 document.getElementById("div1").style.display = "";
40 }
41 else {
42 alert("您的IP地址拒绝访问网站!");
43 window.location.href = "http://www.baidu.com";
44 }
45 });
46 });
47 </script>
备注:html文件页面div1嵌套

 

相关文章:

  • 2021-07-16
  • 2021-10-13
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-31
  • 2021-05-11
  • 2022-01-11
  • 2021-09-04
  • 2022-01-22
  • 2022-01-04
相关资源
相似解决方案