好不容易找到个可以用的,竟然不支持.net的

ascx文件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="IPForward.ascx.cs" Inherits="IPForward" %>
ascx.cs文件
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
public partial class IPForward : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
CheckIP();
}
public void CheckIP()
{
Boolean is_ip_inrange = false;
string testip = "";
String userip = "";
userip = GetIP();
if (testip.Length>0)
{
userip = testip;
}
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\ip.mdb";
string strSQL = "SELECT * FROM ip where ip <> ''";
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand(strSQL, myConn);
OleDbDataReader datareader = null;
try
{
myConn.Open();
datareader = myCmd.ExecuteReader();
while (datareader.Read())
{
String ip_data = datareader["ip"].ToString();
if (userip == ip_data)
{
is_ip_inrange = true;
break;
}
}
}
catch (Exception e)
{
string Message = e.Message;
Response.Write("ERR:" + Message);
}
finally
{
myConn.Close();
}
if (is_ip_inrange)
{
Response.Write("notice");
//Response.Redirect("http://localhost");
Response.End();
}
}
public string GetIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
}