.net 中的 blob 下载计数器
我需要添加一个下载计数器来了解从数据库读取和显示我的 BLOB 数据的次数(以确定流量)。如何以及在哪里添加此计数器?非常感谢!
我有一个动态生成的链接列表,例如 文档文件名
,指向显示页面。
我的显示页面代码如下所示:
Protected Sub Page_Load
Dim DocID As Integer = Convert.ToInt32(Request.QueryString("DocID"))
Dim connStr As String = conn string here
Dim SqlCmd1 As String = "SELECT DocID, DocBD, Filename, MIMEType WHERE DocID=@DocID"
Dim conn As SqlConnection = New SqlConnection(connStr)
Dim Cmd1 As SqlCommand = New SqlCommand(sqlCmd1, conn)
With Cmd1.Parameters
.Add(New SqlParameter("@DocID", DocID)
End With
Try
conn.Open()
Dim myReader As SqlDataReader = Cmd1.ExecuteReader
If myReader.Read Then
Response.ClearContent()
Response.AddHeader("content-disposition", "inline; filename=" & myReader("Filename"))
Response.ContentType = myReader("MIMEType").ToString()
Response.BinaryWrite(myReader("DocBD"))
Response.End()
Else
Label1.Text = "The document you requested doesn't exist in the database. Please contact the document owner"
End If
myReader.Close()
Catch ex As Exception
Label1.Text = ex.Message()
Finally
conn.Close()
End Try
End Sub
I need to add a download counter to know how many times my BLOB data is read and displayed from the database (to determine traffic). How and where can I add this counter? Many thanks!
I have a dynamically generated list of links such as<a href="page.aspx?DocID=IDhere">
Document filename</a>
which direct to a display page.
My display page code looks like:
Protected Sub Page_Load
Dim DocID As Integer = Convert.ToInt32(Request.QueryString("DocID"))
Dim connStr As String = conn string here
Dim SqlCmd1 As String = "SELECT DocID, DocBD, Filename, MIMEType WHERE DocID=@DocID"
Dim conn As SqlConnection = New SqlConnection(connStr)
Dim Cmd1 As SqlCommand = New SqlCommand(sqlCmd1, conn)
With Cmd1.Parameters
.Add(New SqlParameter("@DocID", DocID)
End With
Try
conn.Open()
Dim myReader As SqlDataReader = Cmd1.ExecuteReader
If myReader.Read Then
Response.ClearContent()
Response.AddHeader("content-disposition", "inline; filename=" & myReader("Filename"))
Response.ContentType = myReader("MIMEType").ToString()
Response.BinaryWrite(myReader("DocBD"))
Response.End()
Else
Label1.Text = "The document you requested doesn't exist in the database. Please contact the document owner"
End If
myReader.Close()
Catch ex As Exception
Label1.Text = ex.Message()
Finally
conn.Close()
End Try
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这会对您有所帮助。这是用于上传的,但也许您可以将其用作下载的参考。
Hopefully this will help you out. It's for uploading, but maybe you can use it as a reference for downloading.