By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Missing Web log Entry's for file downloads using ashx

P: n/a
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

Aug 26 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,
Based on my understanding you created an HttpHandler to handle the request
to .ashx, check the user's right and send the file back. But I'm not sure
what do you mean by "but the W3SVC IIS log has nothing". Do you mean the
request to .ashx is not logged?
I created a new HttpHandler to test it and it works fine. Here's my code:
In Web.Config:
<httpHandlers>

<add verb="*" path="*.ashx" type="LogComponent.MyHandler" />
MyHandler.vb:
Namespace LogComponent

Public Class MyHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal ctx As HttpContext)
'do something
response.Write("Your access is registered in my server !")
End Sub
Public ReadOnly Property IsReusable() As Boolean
Get
Return True
End Get
End Property
End Class
End Namespace

I deployed the web application on IIS 5.1. The log path is
C:\WINDOWS\system32\Logfiles. I checked the log file in MSFTPSVC1 folder.
Each time when I access *.ashx there's a new entry added.

Could you check if logging is enabled in IIS and the path is correct? Can
you see the log when you access it in the browser directly instead of using
WGet tool?

If it still doesn't work could you tell me what version of IIS are you
using? It will help me to troubleshoot further.
Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Thread-Topic: Missing Web log Entry's for file downloads using ashx
| thread-index: AckHqFrM373Es0nmSI69ThkADoUrnA==
| X-WBNR-Posting-Host: 207.46.193.207
| From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| Subject: Missing Web log Entry's for file downloads using ashx
| Date: Tue, 26 Aug 2008 11:20:01 -0700
| Lines: 87
| Message-ID: <69**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74661
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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
|
|

Aug 27 '08 #2

P: n/a
Hi,
I am using IIS6, and you are correct, it is not logging the request to the
..ashx when a file is returned to the user (i.e. good credentials and file
requested exists); this executes the part of the if containing the
transmitfile method call. However, a request IS logged if the user requests
a file that doesn't exist or they provide invalid credentials (basically any
logic path that doesn't include the transmitfile method call). It would
appear that the inherited class doing the logging to the web log isn't when
the transmitfile method is called. It does the same thing whether I use IE
or WGet.
Thanks.
"Allen Chen [MSFT]" wrote:
Hi,
Based on my understanding you created an HttpHandler to handle the request
to .ashx, check the user's right and send the file back. But I'm not sure
what do you mean by "but the W3SVC IIS log has nothing". Do you mean the
request to .ashx is not logged?
I created a new HttpHandler to test it and it works fine. Here's my code:
In Web.Config:
<httpHandlers>

<add verb="*" path="*.ashx" type="LogComponent.MyHandler" />
MyHandler.vb:
Namespace LogComponent

Public Class MyHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal ctx As HttpContext)
'do something
response.Write("Your access is registered in my server !")
End Sub
Public ReadOnly Property IsReusable() As Boolean
Get
Return True
End Get
End Property
End Class
End Namespace

I deployed the web application on IIS 5.1. The log path is
C:\WINDOWS\system32\Logfiles. I checked the log file in MSFTPSVC1 folder.
Each time when I access *.ashx there's a new entry added.

Could you check if logging is enabled in IIS and the path is correct? Can
you see the log when you access it in the browser directly instead of using
WGet tool?

If it still doesn't work could you tell me what version of IIS are you
using? It will help me to troubleshoot further.
Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Thread-Topic: Missing Web log Entry's for file downloads using ashx
| thread-index: AckHqFrM373Es0nmSI69ThkADoUrnA==
| X-WBNR-Posting-Host: 207.46.193.207
| From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| Subject: Missing Web log Entry's for file downloads using ashx
| Date: Tue, 26 Aug 2008 11:20:01 -0700
| Lines: 87
| Message-ID: <69**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74661
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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
|
|

Aug 27 '08 #3

P: n/a
Hi,

I cannot reproduce this problem on a Windows 2003 R2 machine with IIS 6
installed. From your description it's caused by the execution of the code
after the user has been authenticated. So I tried this:

Public Class MyHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext)
Dim response As HttpResponse = context.Response
Dim strFileName As String = context.Request.QueryString("file")
If String.IsNullOrEmpty(strFileName) = False Then
strFileName = context.Server.MapPath(strFileName)
Dim fi As FileInfo = New System.IO.FileInfo(strFileName)
context.Response.Clear()

context.Response.StatusCode = 200
context.Response.ContentType = "application/zip"
context.Response.AddHeader("Content-Disposition", "attachment;
filename=" & strFileName)
context.Response.AddHeader("Content-Length", fi.Length.ToString())
context.Response.SuppressContent = False
context.Response.Buffer = False
context.Response.BufferOutput = False

context.Response.TransmitFile(strFileName,0,-1)

context.Response.Flush()
context.Response.Close()

End If
End Sub
Public ReadOnly Property IsReusable() As Boolean
Get
Return False
End Get
End Property
End Class

Basically I used the code in the logic path after the user is
authenticated, including calling TransmitFile method, which as you said, is
the culprit.

However, the log appears as normal when I request something like
http://localhost/.../1.ashx?file=1.zip and the file is successfully
downloaded.

Because I cannot reproduce it I have the following suggestions:

1. Please create a new project and use above code to test. Request the ashx
via IE on the server machine using localhost. Thus we can make sure our
repro steps are same. Can you see the log in this way? If you can see the
log you can add other code blocks one by one until finding the culprit.

2. Please note in IIS 6 the log will not be flushed to the disk
immediately. Considering the performance the log will be buffered and
flushed to disk every 60 seconds by default. Please wait several minutes to
make sure that the log has not been added.

3. If you still cannot see the log using my code please tell me the
operating system you'd using and I'll try to reproduce it again in the same
environment.

Actually, as far as I know, IIS will log all the requests unless a
component in IIS has crashed, which happens uncommonly. I am looking
forward to your test result.

Regards,
Allen Chen
Microsoft Online Support

--------------------
| Thread-Topic: Missing Web log Entry's for file downloads using ashx
| thread-index: AckIWKbuG7vlRWcvRveDaY7wru6RMQ==
| X-WBNR-Posting-Host: 207.46.192.207
| From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| References: <69**********************************@microsoft.co m>
<Cf**************@TK2MSFTNGHUB02.phx.gbl>
| Subject: RE: Missing Web log Entry's for file downloads using ashx
| Date: Wed, 27 Aug 2008 08:22:00 -0700
| Lines: 201
| Message-ID: <85**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74747
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
| I am using IIS6, and you are correct, it is not logging the request to
the
| .ashx when a file is returned to the user (i.e. good credentials and file
| requested exists); this executes the part of the if containing the
| transmitfile method call. However, a request IS logged if the user
requests
| a file that doesn't exist or they provide invalid credentials (basically
any
| logic path that doesn't include the transmitfile method call). It would
| appear that the inherited class doing the logging to the web log isn't
when
| the transmitfile method is called. It does the same thing whether I use
IE
| or WGet.
| Thanks.
| "Allen Chen [MSFT]" wrote:
|
| Hi,
| Based on my understanding you created an HttpHandler to handle the
request
| to .ashx, check the user's right and send the file back. But I'm not
sure
| what do you mean by "but the W3SVC IIS log has nothing". Do you mean
the
| request to .ashx is not logged?
| I created a new HttpHandler to test it and it works fine. Here's my
code:
| In Web.Config:
| <httpHandlers>
| >
| <add verb="*" path="*.ashx" type="LogComponent.MyHandler" />
| MyHandler.vb:
| Namespace LogComponent
| >
| Public Class MyHandler
| Implements IHttpHandler
| Public Sub ProcessRequest(ByVal ctx As HttpContext)
| 'do something
| response.Write("Your access is registered in my server !")
| End Sub
| Public ReadOnly Property IsReusable() As Boolean
| Get
| Return True
| End Get
| End Property
| End Class
| >
| >
| End Namespace
| >
| I deployed the web application on IIS 5.1. The log path is
| C:\WINDOWS\system32\Logfiles. I checked the log file in MSFTPSVC1
folder.
| Each time when I access *.ashx there's a new entry added.
| >
| Could you check if logging is enabled in IIS and the path is correct?
Can
| you see the log when you access it in the browser directly instead of
using
| WGet tool?
| >
| If it still doesn't work could you tell me what version of IIS are you
| using? It will help me to troubleshoot further.
| Regards,
| Allen Chen
| Microsoft Online Support
| >
| Delighting our customers is our #1 priority. We welcome your comments
and
| suggestions about how we can improve the support we provide to you.
Please
| feel free to let my manager know what you think of the level of service
| provided. You can send feedback directly to my manager at:
| ms****@microsoft.com.
| >
| ==================================================
| Get notification to my posts through email? Please refer to
| >
http://msdn.microsoft.com/subscripti...ult.aspx#notif
| ications.
| >
| Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
| where an initial response from the community or a Microsoft Support
| Engineer within 1 business day is acceptable. Please note that each
follow
| up response may take approximately 2 business days as the support
| professional working with you may need further investigation to reach
the
| most efficient resolution. The offering is not appropriate for
situations
| that require urgent, real-time or phone-based interactions or complex
| project analysis and dump analysis issues. Issues of this nature are
best
| handled working with a dedicated Microsoft Support Engineer by
contacting
| Microsoft Customer Support Services (CSS) at
| http://msdn.microsoft.com/subscripti...t/default.aspx.
| ==================================================
| This posting is provided "AS IS" with no warranties, and confers no
rights.
| >
| --------------------
| | Thread-Topic: Missing Web log Entry's for file downloads using ashx
| | thread-index: AckHqFrM373Es0nmSI69ThkADoUrnA==
| | X-WBNR-Posting-Host: 207.46.193.207
| | From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| | Subject: Missing Web log Entry's for file downloads using ashx
| | Date: Tue, 26 Aug 2008 11:20:01 -0700
| | Lines: 87
| | Message-ID: <69**********************************@microsoft.co m>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="Utf-8"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | Content-Class: urn:content-classes:message
| | Importance: normal
| | Priority: normal
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | Path: TK2MSFTNGHUB02.phx.gbl
| | Xref: TK2MSFTNGHUB02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:74661
| | NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | 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
| |
| |
| >
| >
|

Aug 29 '08 #4

P: n/a
Hi,

Thanks for your reply.

After some testing, I found that the culprit was lack of a call
context.Response.Close(). In my post there was a call to
context.Response.Close(), but in the code I was testing with it was missing
for some reason.

I am not sure why it is necessary to call context.Response.Close() after a
call to context.Response.TransmitFile(), but without it, a log entry is not
written. When the call to context.Response.TransmitFile() is removed, the
call to context.Response.Close() is not necessary to write a IIS log entry --
one will be written either way.

Thanks again.
"Allen Chen [MSFT]" wrote:
Hi,

I cannot reproduce this problem on a Windows 2003 R2 machine with IIS 6
installed. From your description it's caused by the execution of the code
after the user has been authenticated. So I tried this:

Public Class MyHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext)
Dim response As HttpResponse = context.Response
Dim strFileName As String = context.Request.QueryString("file")
If String.IsNullOrEmpty(strFileName) = False Then
strFileName = context.Server.MapPath(strFileName)
Dim fi As FileInfo = New System.IO.FileInfo(strFileName)
context.Response.Clear()

context.Response.StatusCode = 200
context.Response.ContentType = "application/zip"
context.Response.AddHeader("Content-Disposition", "attachment;
filename=" & strFileName)
context.Response.AddHeader("Content-Length", fi.Length.ToString())
context.Response.SuppressContent = False
context.Response.Buffer = False
context.Response.BufferOutput = False

context.Response.TransmitFile(strFileName,0,-1)

context.Response.Flush()
context.Response.Close()

End If
End Sub
Public ReadOnly Property IsReusable() As Boolean
Get
Return False
End Get
End Property
End Class

Basically I used the code in the logic path after the user is
authenticated, including calling TransmitFile method, which as you said, is
the culprit.

However, the log appears as normal when I request something like
http://localhost/.../1.ashx?file=1.zip and the file is successfully
downloaded.

Because I cannot reproduce it I have the following suggestions:

1. Please create a new project and use above code to test. Request the ashx
via IE on the server machine using localhost. Thus we can make sure our
repro steps are same. Can you see the log in this way? If you can see the
log you can add other code blocks one by one until finding the culprit.

2. Please note in IIS 6 the log will not be flushed to the disk
immediately. Considering the performance the log will be buffered and
flushed to disk every 60 seconds by default. Please wait several minutes to
make sure that the log has not been added.

3. If you still cannot see the log using my code please tell me the
operating system you'd using and I'll try to reproduce it again in the same
environment.

Actually, as far as I know, IIS will log all the requests unless a
component in IIS has crashed, which happens uncommonly. I am looking
forward to your test result.

Regards,
Allen Chen
Microsoft Online Support
Aug 29 '08 #5

P: n/a
Hi,

I noticed one side-effect of using context.Response.Close() is that the
request never finishes. If you monitor the performance counter
'ASP.NET\Requests Current' it will increase 1 for every request to the .ashx
page until the application pool is recycled. When the call to
context.Response.Close() is removed no web log entry is written, but the
counter 'ASP.NET\Requests Current' does not increase with each request .
According to
<http://www.improve.dk/blog/2008/03/29/response-transmitfile-close-will-kill-your-application>
this combination of calls causes the connections to stick in the send-data
state. It would seem in all this there is a bug in the TransmitFile method.
Can you confirm this behavior?

How can I get the request to write entries in the web log AND not increase
the counter 'ASP.NET\Requests Current'?

Thanks.
"AOTX San Antonio" wrote:
Hi,

Thanks for your reply.

After some testing, I found that the culprit was lack of a call
context.Response.Close(). In my post there was a call to
context.Response.Close(), but in the code I was testing with it was missing
for some reason.

I am not sure why it is necessary to call context.Response.Close() after a
call to context.Response.TransmitFile(), but without it, a log entry is not
written. When the call to context.Response.TransmitFile() is removed, the
call to context.Response.Close() is not necessary to write a IIS log entry --
one will be written either way.

Thanks again.
"Allen Chen [MSFT]" wrote:
Hi,

I cannot reproduce this problem on a Windows 2003 R2 machine with IIS 6
installed. From your description it's caused by the execution of the code
after the user has been authenticated. So I tried this:

Public Class MyHandler
Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext)
Dim response As HttpResponse = context.Response
Dim strFileName As String = context.Request.QueryString("file")
If String.IsNullOrEmpty(strFileName) = False Then
strFileName = context.Server.MapPath(strFileName)
Dim fi As FileInfo = New System.IO.FileInfo(strFileName)
context.Response.Clear()

context.Response.StatusCode = 200
context.Response.ContentType = "application/zip"
context.Response.AddHeader("Content-Disposition", "attachment;
filename=" & strFileName)
context.Response.AddHeader("Content-Length", fi.Length.ToString())
context.Response.SuppressContent = False
context.Response.Buffer = False
context.Response.BufferOutput = False

context.Response.TransmitFile(strFileName,0,-1)

context.Response.Flush()
context.Response.Close()

End If
End Sub
Public ReadOnly Property IsReusable() As Boolean
Get
Return False
End Get
End Property
End Class

Basically I used the code in the logic path after the user is
authenticated, including calling TransmitFile method, which as you said, is
the culprit.

However, the log appears as normal when I request something like
http://localhost/.../1.ashx?file=1.zip and the file is successfully
downloaded.

Because I cannot reproduce it I have the following suggestions:

1. Please create a new project and use above code to test. Request the ashx
via IE on the server machine using localhost. Thus we can make sure our
repro steps are same. Can you see the log in this way? If you can see the
log you can add other code blocks one by one until finding the culprit.

2. Please note in IIS 6 the log will not be flushed to the disk
immediately. Considering the performance the log will be buffered and
flushed to disk every 60 seconds by default. Please wait several minutes to
make sure that the log has not been added.

3. If you still cannot see the log using my code please tell me the
operating system you'd using and I'll try to reproduce it again in the same
environment.

Actually, as far as I know, IIS will log all the requests unless a
component in IIS has crashed, which happens uncommonly. I am looking
forward to your test result.

Regards,
Allen Chen
Microsoft Online Support
Aug 29 '08 #6

P: n/a
Hi,

Thanks for your update. I've reproduced it on my side. Based on my testing
I noticed it's caused by this line:
context.Response.AddHeader("Content-Length", intFileSize.ToString())

Please try to remove it and don't call context.Response.Close(). It will
work fine in this way on my side.

In my opinion, it should not behave like this, though. I'll keep
investigating this issue and get back to you if I find anything valuable.

Regards,
Allen Chen
Microsoft Online Support

--------------------
| Thread-Topic: Missing Web log Entry's for file downloads using ashx
| thread-index: AckKF4yXk+2vWAFfQm2zGnMOB8A1Eg==
| X-WBNR-Posting-Host: 207.46.19.168
| From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| References: <69**********************************@microsoft.co m>
<Cf**************@TK2MSFTNGHUB02.phx.gbl>
<85**********************************@microsoft.co m>
<Sc**************@TK2MSFTNGHUB02.phx.gbl>
<53**********************************@microsoft.co m>
| Subject: RE: Missing Web log Entry's for file downloads using ashx
| Date: Fri, 29 Aug 2008 13:41:01 -0700
| Lines: 111
| Message-ID: <43**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74936
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I noticed one side-effect of using context.Response.Close() is that the
| request never finishes. If you monitor the performance counter
| 'ASP.NET\Requests Current' it will increase 1 for every request to the
..ashx
| page until the application pool is recycled. When the call to
| context.Response.Close() is removed no web log entry is written, but the
| counter 'ASP.NET\Requests Current' does not increase with each request .
| According to
|
<http://www.improve.dk/blog/2008/03/2...lose-will-kill
-your-application>
| this combination of calls causes the connections to stick in the
send-data
| state. It would seem in all this there is a bug in the TransmitFile
method.
| Can you confirm this behavior?
|
| How can I get the request to write entries in the web log AND not
increase
| the counter 'ASP.NET\Requests Current'?
|
| Thanks.
| "AOTX San Antonio" wrote:
|
| Hi,
| >
| Thanks for your reply.
| >
| After some testing, I found that the culprit was lack of a call
| context.Response.Close(). In my post there was a call to
| context.Response.Close(), but in the code I was testing with it was
missing
| for some reason.
| >
| I am not sure why it is necessary to call context.Response.Close()
after a
| call to context.Response.TransmitFile(), but without it, a log entry is
not
| written. When the call to context.Response.TransmitFile() is removed,
the
| call to context.Response.Close() is not necessary to write a IIS log
entry --
| one will be written either way.
| >
| Thanks again.
| "Allen Chen [MSFT]" wrote:
| >
| Hi,
|
| I cannot reproduce this problem on a Windows 2003 R2 machine with IIS
6
| installed. From your description it's caused by the execution of the
code
| after the user has been authenticated. So I tried this:
|
| Public Class MyHandler
| Implements IHttpHandler
| Public Sub ProcessRequest(ByVal context As HttpContext)
| Dim response As HttpResponse = context.Response
| Dim strFileName As String = context.Request.QueryString("file")
| If String.IsNullOrEmpty(strFileName) = False Then
| strFileName = context.Server.MapPath(strFileName)
| Dim fi As FileInfo = New System.IO.FileInfo(strFileName)
| context.Response.Clear()
|
| context.Response.StatusCode = 200
| context.Response.ContentType = "application/zip"
| context.Response.AddHeader("Content-Disposition", "attachment;
| filename=" & strFileName)
| context.Response.AddHeader("Content-Length",
fi.Length.ToString())
|
|
| context.Response.SuppressContent = False
| context.Response.Buffer = False
| context.Response.BufferOutput = False
|
| context.Response.TransmitFile(strFileName,0,-1)
|
| context.Response.Flush()
| context.Response.Close()
|
| End If
| End Sub
| Public ReadOnly Property IsReusable() As Boolean
| Get
| Return False
| End Get
| End Property
| End Class
|
| Basically I used the code in the logic path after the user is
| authenticated, including calling TransmitFile method, which as you
said, is
| the culprit.
|
| However, the log appears as normal when I request something like
| http://localhost/.../1.ashx?file=1.zip and the file is successfully
| downloaded.
|
| Because I cannot reproduce it I have the following suggestions:
|
| 1. Please create a new project and use above code to test. Request
the ashx
| via IE on the server machine using localhost. Thus we can make sure
our
| repro steps are same. Can you see the log in this way? If you can see
the
| log you can add other code blocks one by one until finding the
culprit.
|
| 2. Please note in IIS 6 the log will not be flushed to the disk
| immediately. Considering the performance the log will be buffered and
| flushed to disk every 60 seconds by default. Please wait several
minutes to
| make sure that the log has not been added.
|
| 3. If you still cannot see the log using my code please tell me the
| operating system you'd using and I'll try to reproduce it again in
the same
| environment.
|
| Actually, as far as I know, IIS will log all the requests unless a
| component in IIS has crashed, which happens uncommonly. I am looking
| forward to your test result.
|
| Regards,
| Allen Chen
| Microsoft Online Support
|
|

Sep 2 '08 #7

P: n/a
Hi,

Based on my research this issue is related to Asp.NET internal mechanism
that somehow hangs the request. You're welcome to submit a feedback on the
connect to notify our development team:
http://connect.microsoft.com/VisualStudio/Feedback

Your valuable feedback will help to improve our products.

Thanks,
Allen Chen
Microsoft Online Support

--------------------
| Thread-Topic: Missing Web log Entry's for file downloads using ashx
| thread-index: AckKF4yXk+2vWAFfQm2zGnMOB8A1Eg==
| X-WBNR-Posting-Host: 207.46.19.168
| From: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= <El******@newsgroup.nospam>
| References: <69**********************************@microsoft.co m>
<Cf**************@TK2MSFTNGHUB02.phx.gbl>
<85**********************************@microsoft.co m>
<Sc**************@TK2MSFTNGHUB02.phx.gbl>
<53**********************************@microsoft.co m>
| Subject: RE: Missing Web log Entry's for file downloads using ashx
| Date: Fri, 29 Aug 2008 13:41:01 -0700
| Lines: 111
| Message-ID: <43**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Path: TK2MSFTNGHUB02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:74936
| NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| I noticed one side-effect of using context.Response.Close() is that the
| request never finishes. If you monitor the performance counter
| 'ASP.NET\Requests Current' it will increase 1 for every request to the
ashx
| page until the application pool is recycled. When the call to
| context.Response.Close() is removed no web log entry is written, but the
| counter 'ASP.NET\Requests Current' does not increase with each request .
| According to
|
<http://www.improve.dk/blog/2008/03/2...lose-will-kill
-your-application>
| this combination of calls causes the connections to stick in the
send-data
| state. It would seem in all this there is a bug in the TransmitFile
method.
| Can you confirm this behavior?
|
| How can I get the request to write entries in the web log AND not
increase
| the counter 'ASP.NET\Requests Current'?
|
| Thanks.
| "AOTX San Antonio" wrote:
|
| Hi,
| >
| Thanks for your reply.
| >
| After some testing, I found that the culprit was lack of a call
| context.Response.Close(). In my post there was a call to
| context.Response.Close(), but in the code I was testing with it was
missing
| for some reason.
| >
| I am not sure why it is necessary to call context.Response.Close()
after a
| call to context.Response.TransmitFile(), but without it, a log entry is
not
| written. When the call to context.Response.TransmitFile() is removed,
the
| call to context.Response.Close() is not necessary to write a IIS log
entry --
| one will be written either way.
| >
| Thanks again.
| "Allen Chen [MSFT]" wrote:
| >
| Hi,
|
| I cannot reproduce this problem on a Windows 2003 R2 machine with IIS
6
| installed. From your description it's caused by the execution of the
code
| after the user has been authenticated. So I tried this:
|
| Public Class MyHandler
| Implements IHttpHandler
| Public Sub ProcessRequest(ByVal context As HttpContext)
| Dim response As HttpResponse = context.Response
| Dim strFileName As String = context.Request.QueryString("file")
| If String.IsNullOrEmpty(strFileName) = False Then
| strFileName = context.Server.MapPath(strFileName)
| Dim fi As FileInfo = New System.IO.FileInfo(strFileName)
| context.Response.Clear()
|
| context.Response.StatusCode = 200
| context.Response.ContentType = "application/zip"
| context.Response.AddHeader("Content-Disposition", "attachment;
| filename=" & strFileName)
| context.Response.AddHeader("Content-Length",
fi.Length.ToString())
|
|
| context.Response.SuppressContent = False
| context.Response.Buffer = False
| context.Response.BufferOutput = False
|
| context.Response.TransmitFile(strFileName,0,-1)
|
| context.Response.Flush()
| context.Response.Close()
|
| End If
| End Sub
| Public ReadOnly Property IsReusable() As Boolean
| Get
| Return False
| End Get
| End Property
| End Class
|
| Basically I used the code in the logic path after the user is
| authenticated, including calling TransmitFile method, which as you
said, is
| the culprit.
|
| However, the log appears as normal when I request something like
| http://localhost/.../1.ashx?file=1.zip and the file is successfully
| downloaded.
|
| Because I cannot reproduce it I have the following suggestions:
|
| 1. Please create a new project and use above code to test. Request
the ashx
| via IE on the server machine using localhost. Thus we can make sure
our
| repro steps are same. Can you see the log in this way? If you can see
the
| log you can add other code blocks one by one until finding the
culprit.
|
| 2. Please note in IIS 6 the log will not be flushed to the disk
| immediately. Considering the performance the log will be buffered and
| flushed to disk every 60 seconds by default. Please wait several
minutes to
| make sure that the log has not been added.
|
| 3. If you still cannot see the log using my code please tell me the
| operating system you'd using and I'll try to reproduce it again in
the same
| environment.
|
| Actually, as far as I know, IIS will log all the requests unless a
| component in IIS has crashed, which happens uncommonly. I am looking
| forward to your test result.
|
| Regards,
| Allen Chen
| Microsoft Online Support
|
|

Sep 8 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.