ASP.NET 4 Unleased - p 152
lượt xem 5
download
Working with the HTTP Runtime private private private private string _conString; SqlConnection _con; SqlCommand _cmdSelect; SqlCommand _cmdInsert; public override void Init() { // initialize connection _conString = ➥WebConfigurationManager.ConnectionStrings[“Log”].ConnectionString; _con = new SqlConnection(_conString); // initialize select command _cmdSelect = new SqlCommand(“SELECT COUNT(*) FROM Log WHERE Path=@Path”, ➥_con); _cmdSelect.Parameters.Add(“@Path”, SqlDbType.NVarChar, 500); // initialize insert command _cmdInsert = new SqlCommand(“INSERT Log (Path) VALUES (@Path)”, _con); _cmdInsert.Parameters.Add(“@Path”, SqlDbType.NVarChar, 500); } public int NumberOfRequests { get { int result = 0; _cmdSelect.Parameters[“@Path”].Value = Request.AppRelativeCurrentExecutionFilePath; try { _con.Open(); result = (int)_cmdSelect.ExecuteScalar(); } finally { _con.Close(); } return result; } } void Application_BeginRequest(object sender,...
Bình luận(0) Đăng nhập để gửi bình luận!
CÓ THỂ BẠN MUỐN DOWNLOAD