日期:2014-05-17 浏览次数:20629 次
public string hits_ip;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["cip"]==null)
{
if (Request.ServerVariables["HTTP_VIA"] != null)
{
hits_ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
hits_ip = Request.UserHostAddress;
}
Response.Cookies.Add(new HttpCookie("cip", hits_ip));
Response.Cookies["cip"].Expires = DateTime.Now.AddDays(1);
string str = System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["dbPath"]);
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + str);
myConn.Open();
OleDbCommand myCommand = new OleDbCommand("UPDATE [table] SET Hits=Hits+1 WHERE NewsId='" + Request.QueryString["id"] + "'", myConn);
myCommand.ExecuteNonQuery();
myConn.Close();
}
}
}