Web sayfamızı ziyaret eden ziyaretçilerin hangi sayfalara girdikleri, ip numaralarını, giriş tarihlerini, hangi tarayıcı kullandıklarını kaydedeceğiz. Bunun için Global.asax ta
Application_BeginRequest(object sender, EventArgs e) e aşağıdaki kodları yazacağız.
Global.asax
< %@ Import Namespace="System.Data.OleDb" % >
< %@ Application Language="C#" % >
< %@ Import Namespace="System.Data.OleDb" % >
< %@ Application Language="C#" % >
< runat="server">
protected void Application_BeginRequest(object sender, EventArgs e)
{
string str = "Insert into ziyaretci (url,sayfa,ip,kaynak,tarih) values(@url,@sayfa,@ip,@kaynak,@tarih)";
OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");
OleDbCommand komut = new OleDbCommand(str, baglan);
komut.Parameters.AddWithValue("@url", Request.ServerVariables["URL"].ToString());
komut.Parameters.AddWithValue("@sayfa", Request.ServerVariables["Query_String"].ToString());
komut.Parameters.AddWithValue("@ip", Request.ServerVariables["Remote_Addr"].ToString());
komut.Parameters.AddWithValue("@kaynak", Request.ServerVariables["Http_User_Agent"].ToString());
komut.Parameters.AddWithValue("@tarih", DateTime.Now.ToString());
baglan.Open();
komut.ExecuteNonQuery();
baglan.Close();
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
< / script >
Default.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "Select * From ziyaretci";
OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");
OleDbDataAdapter adp = new OleDbDataAdapter(str, baglan);
OleDbCommand komut = new OleDbCommand(str, baglan);
baglan.Open();
DataSet ds= new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
baglan.Close();
}
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
string str = "Insert into ziyaretci (url,sayfa,ip,kaynak,tarih) values(@url,@sayfa,@ip,@kaynak,@tarih)";
OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");
OleDbCommand komut = new OleDbCommand(str, baglan);
komut.Parameters.AddWithValue("@url", Request.ServerVariables["URL"].ToString());
komut.Parameters.AddWithValue("@sayfa", Request.ServerVariables["Query_String"].ToString());
komut.Parameters.AddWithValue("@ip", Request.ServerVariables["Remote_Addr"].ToString());
komut.Parameters.AddWithValue("@kaynak", Request.ServerVariables["Http_User_Agent"].ToString());
komut.Parameters.AddWithValue("@tarih", DateTime.Now.ToString());
baglan.Open();
komut.ExecuteNonQuery();
baglan.Close();
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
< / script >
Default.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "Select * From ziyaretci";
OleDbConnection baglan = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/bilgi.accdb") + "; Persist Security Info=False;");
OleDbDataAdapter adp = new OleDbDataAdapter(str, baglan);
OleDbCommand komut = new OleDbCommand(str, baglan);
baglan.Open();
DataSet ds= new DataSet();
adp.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
baglan.Close();
}
}
Default.aspx.cs
Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek dileğiyle. Hoşçakalın. Bahadır ŞAHİN
1 comments:
Açıklayıcı bilgiler için teşekkürler.
Yorum Gönder