Missing Web log Entry's for file downloads

A

AOTX San Antonio

Hi,

I have been using the code (some of it has been removed for simplicity)
below to allow authenticated (using ASP.NET membership database) users to get
a file from their archive area. It seems to work fine, however I noticed
that no web log entry is added when a successful download occurs (normally a
200 HTTP status code, however, if there is an authorization failure, it gets
logged). I have a logging routine that logs a successful download to a
database, but the W3SVC IIS log has nothing. The code below is contained in
an .ashx file. One other thing to note, I have added MADAM to the web
application, to allow for basic authentication (they might use WGET to
download archives, instead of the web forms).

Thanks.

Public Class GetArchive : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements
IHttpHandler.ProcessRequest
Dim strFileName As String = String.Empty
Dim blnTransmittingFile As Boolean = False
Try
context.Response.Buffer = True
If context.User.Identity.IsAuthenticated = True Then
strFileName = context.Request.QueryString("file")
If String.IsNullOrEmpty(strFileName) = False Then
strFileName = System.IO.Path.GetFileName(strFileName)
context.Response.Clear()

Dim objFileInfo As New System.IO.FileInfo(strFileName)
Dim intFileSize As Long = 0

If objFileInfo IsNot Nothing Then
intFileSize = objFileInfo.Length
End If

context.Response.StatusCode = 200
context.Response.ContentType = "application/zip"
context.Response.AddHeader("Content-Disposition",
"attachment; filename=" + strFileName)
context.Response.AddHeader("Content-Length",
intFileSize.ToString())

If context.Request.HttpMethod <> "HEAD" Then
Dim dtStart As DateTime = Now()
Dim dtFinish As DateTime
Dim tsTimeTaken As TimeSpan
context.Response.SuppressContent = False
context.Response.Buffer = False
context.Response.BufferOutput = False
blnTransmittingFile = True
context.Response.TransmitFile(strFileName, 0, -1)
context.Response.Flush()
context.Response.Close()
dtFinish = Now()
tsTimeTaken = dtFinish - dtStart
EventLogger.LogDownloadEvent(strFileName,
strUserName, tsTimeTaken.TotalSeconds)
End If
Else
context.Response.Clear()
context.Response.ContentType = "text/plain"
context.Response.StatusCode = 404
context.Response.Write("File Not Found")
End If
End If

Catch ex As Exception
If blnTransmittingFile = False Then
context.Response.Clear()
context.Response.ClearContent()
context.Response.ClearHeaders()
context.Response.ContentType = "text/plain"
End If
context.Response.StatusCode = 403
context.Response.Write("Request failed [" + ex.ToString() + "]")
EventLogger.LogDownloadEvent("Failed", ex.ToString())
End Try
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements
IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top